livewire-datatables icon indicating copy to clipboard operation
livewire-datatables copied to clipboard

Sorting not working properly

Open ItsJoshDaly opened this issue 3 years ago • 3 comments

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!

ItsJoshDaly avatar Feb 08 '22 10:02 ItsJoshDaly

I found some sorting issues too, and solved by hacking the code vendor/mediconesystems/livewire-datatables/src/Http/Livewire/LivewireDatatable.php at line 727 : replace quote with back ticks ... what do you think

  : new Expression("\`" . $column['name'] . "`");

breizhwave avatar Apr 27 '22 05:04 breizhwave

Using back ticks in this line solved this for me, too.

richmarisa avatar May 04 '22 17:05 richmarisa

That breaks many other database types. Someone has started doing proper database typing but I don't believe it was ever finished.

shaneburrell avatar May 04 '22 20:05 shaneburrell