数据表搜索输入在OctoberCMS中不起作用

时间:2019-07-25 07:14:05

标签: javascript php jquery datatables octobercms

我正在使用OctoberCMS中的数据表服务器端处理。 一切正常,但搜索输入无效。 搜索输入在我在客户端处理中尝试过时效果很好。

Datatables部分Javascript

$(document).ready(function() {
  var tableId = "datalist";
  var table = $('#' + tableId).DataTable({
      processing: true,
      serverSide: true,
      ajax: {
          url: '/ajax?tb={{ tableName|raw() }}&fd={{ fields|raw() }}',
          type: 'GET',
          //tb: 'BYAPPS_apps_data',
          error: function(e) {
            console.log(e);
          }
      },
      paging: true,
      pageLength: 50,
      "info": false,
      "autoWidth": true,
      "fixedHeader": false,
      "responsive": true,
      "orderClasses": false,
      "stateSave": true,
      "dom": 'Bfrtip',
      "buttons": [
          'excel', 'copy'
      ],
  });

  $('.dataTables_filter input').bind('keyup', function () {
      console.log('here');
        table.search(this.value).draw();
    });
});

Ajax部分PHP文件

function onStart()
{
   $table = $_GET['tb'];
   $length = $_GET['length'];
   $start = $_GET['start'];
   $fields = explode("|", $_GET['fd']);

   $result = DB::table($table)->skip($start)->limit($length)->get();
   $data = array();

   foreach($result as $row) {
      $sub_array = array();

      for ($i = 0; $i < count($fields); $i++) {
            $sub_array[] = $row->{$fields[$i]};
      }
      $data[] = $sub_array;
   }

   $output = array(
     "draw" => intval($_GET['draw']),
     "recordsTotal" => DB::table($table)->count(),
     "recordsFiltered" => DB::table($table)->count(),
     "data" => $data,
   );

   echo json_encode($output);
}

如何解决此问题并使搜索输入正常工作?

0 个答案:

没有答案
相关问题