Datatable icon indicating copy to clipboard operation
Datatable copied to clipboard

problem with ->orderBy() in Datatable::query()

Open thearabbit opened this issue 11 years ago • 6 comments
trafficstars

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();

thearabbit avatar Jul 25 '14 12:07 thearabbit

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 avatar Aug 11 '14 17:08 timothyrowan

@timothyrowan You are using a collection with the query engine. Please use a query or the collection engine.

Chumper avatar Aug 11 '14 17:08 Chumper

@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?

Chumper avatar Aug 11 '14 17:08 Chumper

killer, that was it, thanks! great product.

timothyrowan avatar Aug 11 '14 21:08 timothyrowan

Thanks, but i don't understand (i should use query or collection).

thearabbit avatar Aug 12 '14 06:08 thearabbit

@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

Chumper avatar Sep 15 '14 17:09 Chumper