【问题标题】:JQuery DataTables: Server-Side Search Function Breaking with SQL ErrorJQuery DataTables:服务器端搜索功能因 SQL 错误而中断
【发布时间】:2018-06-21 12:18:57
【问题描述】:

我有一个简单的 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
    });

而我被调用的“服务器端”路由看起来像:

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

“Degree”模型完全为空,除了将相应的表定义为“degree_inventory”

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

【问题讨论】:

  • 你用包吗?
  • degree_inventory 从何而来?它是偶然的附加字段吗?它似乎在数据库中不存在,所以它必须从某个地方添加。
  • @Devon 'degree_inventory' 是数据库中的一个视图,它与应用程序其余部分使用的模式相同。它从内的几个不同表中编译信息
  • 我认为这不对。如果您查看 datatables 原始响应,我想您会发现一个名为 degree_inventory 的列,这就是 datatables 包尝试在该列上提交搜索查询的原因。
  • @Alihosseinshahabi 这是常见的 laravel 数据表包 yajrabox.com/docs/laravel-datatables/master

标签: laravel datatables


【解决方案1】:

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

解决方案是禁用展开/折叠列的可搜索属性,因为该列的内容完全是图像。

例如:

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

【讨论】:

    猜你喜欢
    • 2015-10-25
    • 1970-01-01
    • 2016-02-11
    • 2017-12-28
    • 2018-03-13
    • 2011-12-28
    • 2017-06-16
    • 2012-07-18
    • 1970-01-01
    相关资源
    最近更新 更多