MedicOneSystems / MedicOneSystems/livewire-datatables

Sorting not working properly

Open
#391 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
1.2k
Forks
257
PR merge metrics
No merged PRs in 30d

Description

I've been trying to sort the datatables on my project by a certain hidden column - in this case it was "created_at". I had attempted a number of methods and strangely, the only thing that seemed to ever behave correctly was the flag for "asc" or "desc".

For instance, I tried to use the props...

<livewire:tables.companies :excludeTrashed=true sort="created_at|asc"/>

Whether or not the column was visible, it would simply sort by name ascending or descending, although it did change depending on if I used "asc" or "desc" in the props. I also tried setting a public $sort which ended up with similar results. I even tried using the sortBy column method to absolutely no avail.

DateColumn::name('created_at') ->label('Created At') ->sortBy('DATE_FORMAT') ->hide()

I also tried making it searchable and simply just referring to it as if it were a regular column, none of which worked. I can also verify that even filtering by name didn't return the desired data because I had cross-compared what the datatable returned against DataGrip only to find that the ordering was wrong.

Any help would be muchly appreciated, thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported sort on the livewire:tables.companies component with the hidden created_at column. Inspect the DateColumn configuration and sortBy('DATE_FORMAT') usage, then compare the returned order with the database. Done means ascending and descending sorting consistently use created_at rather than the name column.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.