column-sortable icon indicating copy to clipboard operation
column-sortable copied to clipboard

Sorting json column don't work

Open divdax opened this issue 3 years ago • 1 comments

Hi,

i tried to sort by name column (datatype: json) with:

->sortable('name->en')

The database query doesn't contain any order by.

divdax avatar Mar 03 '22 21:03 divdax

Hi, I had the same issue, but debugging how the query is built, I discorver that you can put alias to the order, and that alias are translate to correct JSON order from eloquent.

This is my code:

  • Model
protected array $sortableAs = [
        'name->en',
        'name->es',
    ];
  • View
@sortablelink('name->en')

With this, eloquent generates this:

select * from exercises order by json_unquote(json_extract(name, '$."en"')) asc limit 15 offset 0

JoseVte avatar Jul 28 '22 17:07 JoseVte