Datatable
Datatable copied to clipboard
problem with ->orderBy() in Datatable::query()
I use Datatable::query(), when it set ->orderBy() the ->orderColumns() don't work.
$data = \DB::table('agent')->orderBy('kh_name');
return \Datatable::query($data)
->showColumns('id', 'kh_name', 'en_name', 'sex', 'address', 'telephone', 'email')
->searchColumns('id', 'kh_name', 'en_name', 'sex', 'address')
->orderColumns('id', 'kh_name', 'en_name', 'sex', 'address')
->make();
I am having the same issue without using orderby. my code:
public function getDatatable()
{
return Datatable::query(User::all(array('id','username')))
->showColumns('id', 'username')
->searchColumns('username')
->orderColumns('id','username')
->make();
}
getting a 500 err and hearing this from laravel
Call to undefined method Illuminate\Database\Eloquent\Collection::orderBy()
@timothyrowan You are using a collection with the query engine. Please use a query or the collection engine.
@yuomtheara That is because i dont remove ordering done by the user, so it will order by name first, then by the column, any advice how to change that?
killer, that was it, thanks! great product.
Thanks, but i don't understand (i should use query or collection).
@yuomtheara The problem is, that you pass a sorted query to databale and we do not modify it. In order for ot to work correctly we need to clear your orderings or you need to pass the query without orderings to Datatable