kdion4891 / laravel-livewire-tables

A dynamic, responsive Laravel Livewire table component with searching, sorting, checkboxes, and pagination.
302 stars 41 forks source link

Foreign json column #10

Closed fahmifitu closed 4 years ago

fahmifitu commented 4 years ago

Hello, Great work you put into the package, really simple and useful. I have a quick question, Is there a way of how we can create a column out of json column in a foreign table and make it sortable and searchable?

Thanks

kdion4891 commented 4 years ago

See this:

https://github.com/kdion4891/laravel-livewire-tables#sortusingcallback

fahmifitu commented 4 years ago

See this:

https://github.com/kdion4891/laravel-livewire-tables#sortusingcallback

For some reason that didn't work for me. it returns a SQL syntax error. After some time of debugging, I figured out that the issue is with query binding. Although is not safe, I found a workaround concatenating the sort direction like that works just fine even though it is the same query return $models->orderByRaw('data->\'$.name\' ' . $sort_direction);

You can reproduce the same error with dd(DB::table('users') ->orderByRaw('created_at ?', ['desc']) ->get());

kdion4891 commented 4 years ago

I haven't put much thought into json columns with this package. If you come up with a decent solution, feel free to submit a PR.