Laravel Datatables Column not found at search

Viewed 1283

im working with datatables (yajra) and laravel.

i have working the datatables but i have error when i try to search. "sqlstate 42s22 column not found 1054 unknown column 'customer.' in where clause'"

my controller:

$query = DB::table('customer')->orderBy('id'); 
        return DataTables::queryBuilder($query)->toJson();

My view:

if (dtUserTable.length) {
    dtUserTable.DataTable({
        pageLength: 10,
stateSave: true,
processing: true,
serverSide: true,
      ajax:{url:"customer-list"},
      columns: [
        // columns according to JSON
        { data: 'id' },
        { data: 'fullname' },
        { data: 'num_doc'},
        { data: 'mobile' },
        { data: 'email' },
        { data: 'class' },
        { data: '' }
      ],
      columnDefs: [
        {
          // For Responsive
          className: 'control',
          orderable: false,
          responsivePriority: 2,
          targets: 0
        },

extra: if i use this:

$customers = DB::table('customer')->get();
return json_decode($customers,true);

it work, but not work the server side!

Any can help me to make it work with server side and search? i try some configs and only can make work serverside OR search

1 Answers

I think issue is for mentioning null for data in column array

 { data: '' }

so you can remove that row or you can set defaultContent

 { data: 'column_name',  "defaultContent": "" }

Also you can disable searching

 { data: 'column_name', "searchable": false , "defaultContent": ""  }

Ref:https://datatables.net/forums/discussion/50823/handling-null-values

Related