Closed jonasva closed 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!)
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
What is $locations
? Can you please get me the output of dd (get_class($locations));
$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');
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.
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:
Thanks for your help, much appreciated.
I fear this was actually all my fault. Can you please update the composer package for me please?
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"
OK, I have removed a type hint now which should resolve this problem.
Great it works well now. Thanks @timgws!
:+1: Glad to hear it's all working correctly for you now, @jonasva
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