Chumper / Datatable

This is a laravel 4 package for the server and client side of datatables at http://datatables.net/
https://github.com/Chumper/Datatable
388 stars 154 forks source link

Infinite loop with doInternalSearch after recent updates #322

Closed jonasva closed 9 years ago

jonasva commented 9 years ago

I'm having some issues using dataTables search after fetching the latest updates with composer. When I do an ajax search I get the following error:

file: "/var/www/html/myproj/vendor/chumper/datatable/src/Chumper/Datatable/Engines/QueryEngine.php" line: 274 message: "Maximum function nesting level of '200' reached, aborting!" type: "Symfony\Component\Debug\Exception\FatalErrorException"

I've already tried increasing the maximum function nesting level, but it keeps hitting it.

The issue seems to be that the same functions gets called recursively here: https://github.com/Chumper/Datatable/blob/master/src/Chumper/Datatable/Engines/QueryEngine.php#L274

I'm using the Datatable::query($query) method

timgws commented 9 years ago

@jonasva can you please show me the way that you are calling datatable please? Also, please let me know what branch/version you are using (I am guessing dev-master, but I just want to double check!)

jonasva commented 9 years ago

I use this for the datatable ajax route in my controller:

        return Datatable::query($locations)
            ->showColumns('title', 'weight')
            ->addColumn('published',function($model)
            {
                return $model->published ? '<i class="fa fa-check text-success"><span style="display: none;">1</span></i>' : '<i class="fa fa-close text-danger"><span style="display: none;">0</span></i>';
            })
            ->addColumn('actions',function($model)
            {
                $showBtn = '<a href="'.URL::route('admin.location.show', $model->id).'" class="btn btn-default offset-xs-right"><i class="fa fa-eye"></i></a>';
                $editBtn = '<a href="'.URL::route('admin.location.edit', $model->id).'" class="btn btn-primary offset-xs-right"><i class="fa fa-wrench"></i></a>';
                return $showBtn . $editBtn ;
            })
            ->searchColumns('title')
            ->orderColumns('title', 'weight')
            ->make();

In my view I use this:

    {{ $table = Datatable::table()
        ->addColumn('title', 'order', 'publ.', '<i class="fa fa-cogs"></i>')
        ->setUrl(route('data.locations'))
        ->setOrder(array(1 => 'asc'))
        ->render(); }}

I'm using dev-master indeed, everything was working fine until my last composer update. I checked, and the commit I was on before updating was this one: 33bacbe

timgws commented 9 years ago

What is $locations? Can you please get me the output of dd (get_class($locations));

jonasva commented 9 years ago

$locations contains a query.

        $locations = DB::table('locations')
                ->join('location_translations', function($join)
                {
                    $join->on('locations.id', '=', 'location_translations.location_id')->on('locale', '=', DB::raw('"'.App::getLocale().'"'));
                })
                ->select('locations.id', 'locations.weight', 'location_translations.title', 'location_translations.published', 'location_translations.locale');
timgws commented 9 years ago

Your searchColumns and orderColumns should have the same name of the columns that you are using in your select, because (as far as I recall) the AJAX ordering will try to do the order based on the names provided.

Either way, when I finish work, I will have a further look for you.

jonasva commented 9 years ago

I've tried renaming them, but it doesn't solve the issue.

Actually sorting works fine, it's only searching that has an issue. This is the ajax URL that is generated for a search request:

http://test.test/test?sEcho=3&iColumns=4&sColumns=%2C%2C%2C&iDisplayStart=0&iDisplayLength=10&mDataProp_0=0&sSearch_0=&bRegex_0=false&bSearchable_0=true&bSortable_0=true&mDataProp_1=1&sSearch_1=&bRegex_1=false&bSearchable_1=true&bSortable_1=true&mDataProp_2=2&sSearch_2=&bRegex_2=false&bSearchable_2=true&bSortable_2=true&mDataProp_3=3&sSearch_3=&bRegex_3=false&bSearchable_3=true&bSortable_3=true&sSearch=test&bRegex=false&iSortCol_0=0&sSortDir_0=asc&iSortingCols=1&_=1436427676038

Thanks for your help, much appreciated.

timgws commented 9 years ago

I fear this was actually all my fault. Can you please update the composer package for me please?

jonasva commented 9 years ago

hmm, after updating to your latest commit I get the following error when doing an ajax search:

file: "/var/www/html/myprojl/vendor/chumper/datatable/src/Chumper/Datatable/Engines/QueryEngine.php" line: 289 message: "Argument 1 passed to Chumper\Datatable\Engines\QueryEngine::Chumper\Datatable\Engines{closure}() must be an instance of Illuminate\Database\Eloquent\Builder, instance of Illuminate\Database\Query\Builder given" type: "ErrorException"

timgws commented 9 years ago

OK, I have removed a type hint now which should resolve this problem.

jonasva commented 9 years ago

Great it works well now. Thanks @timgws!

timgws commented 9 years ago

:+1: Glad to hear it's all working correctly for you now, @jonasva