JQuery DataTables:服务器端搜索功能因SQL错误而中断

时间:2018-06-21 12:18:58

标签: laravel datatables

我有一个简单的DataTable,其中填充了数据库中的数据,特别是从名为“ degree_inventory”的视图(而不是传统表)中填充的数据。我的应用程序是用Laravel编写的,因此我使用一条路由来获取数据,该路由提取与模型相对应的所有对象并将它们导入到我的表中。由于该表具有“子行”,但默认情况下不存在这些子级,因此存在另一种复杂性。

我的桌子:

   <table id="program-table" class="table stripe compact">
     <thead>
         <tr>
             <th>Levels</th>
             <th>CIP Code</th>
             <th>CIP Title</th>
             <th>USF Title</th>
             <th>Degree(s)</th>
             <!-- <th>Activated Term</th>
             <th>Suspended Term</th>
             <th>Discontinued Term</th> -->
         </tr>
     </thead>

     <tbody>
     </tbody>
   </table>

我的DT声明如下:

$('#program-table').DataTable({
      processing: true,
      serverSide: true,
      ajax: "{{ route('serverSide') }}",
      columns: [
          {
            "className":      'details-control',
            "orderable":      false,
            "data":           null,
            "width":          '8%',
            "defaultContent": ''
          },
          { data: 'cip', width: '10%'},
          { data: 'cip_title' },
          { data: 'item_name' },
          { data: 'degree_name_list' }
      ],
      pageLength: 25,
      searching: true,
      paging: true,
      fixedHeader: true, //plugin not working
      "order": [[ 1, "asc" ]] //by default order by cip code
    });

被调用的“ serverSide”路由如下所示:

Route::get('/serverSide', [
    'as'   => 'serverSide',
    'uses' => function () {
    $model = \App\Degree::query();
    return DataTables::eloquent($model)->make();
}
]);

“学位”模型完全为空,除了将相应的表定义为“学位库存”

该表最初会填充,展开子行并完美地分页,但是对搜索栏的任何查询都会返回以下错误: 找不到列:1054个“ where子句”中的未知列“ degree_inventory”,后跟原始查询,试图查找与每一行中的条目匹配的内容。 如果有人有任何见识,我将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:0)

问题是我有一列按钮来展开和折叠子行。

解决方案是禁用扩展/折叠列的searchable属性,因为该列的内容仅是图像。

例如:

$('#example').dataTable( {
  "columns": [
    { "searchable": false }, //first column is the expand button
    null,
    null,
    null,
    null
  ] } );
} );