简体   繁体   English

数据表错误:第0行第10列请求的未知参数'10'; 尝试将复选框添加到数据表时

[英]Datatables error: Requested unknown parameter '10' for row 0, column 10; when tried to add checkbox to the datatable

I want to add 'checkbox' in the datatable and I'm handling it as server-side processing. 我想在数据表中添加“复选框”,并将其作为服务器端处理进行处理。 I used this article as a guide. 我以这篇文章为指导。 However it gave me this warning: 但是它给了我这个警告:

DataTables warning: table id=datalist - Requested unknown parameter '10' for row 0, column 10. For more information about this error, please see http://datatables.net/tn/4 DataTables警告:表ID =数据列表-为第0行第10列请求的未知参数'10'。有关此错误的更多信息,请参见http://datatables.net/tn/4

I'm also working in OctoberCMS. 我也在OctoberCMS工作。

php block and html PHP块和HTML

<?php
use Jiwon\Byapps\Models\AppsData;

function onStart()
{
    $this['tableName'] = 'BYAPPS_apps_data';
    $this['fields'] = "app_id|app_name|app_ver|byapps_ver|app_process|script_popup|custom_etc|apps_type|start_time|end_time";
}
?>
<table id="datalist" class="table table-striped mb-3" style="width:100%;">
        <thead>
            <tr>
                <th></th>
                <th>app id</th>
                <th>app name</th>
                <th>ver</th>
                <th>BV</th>
                <th>process</th>
                <th>SCRIPT</th>
                <th>custom</th>
                <th>OS</th>
                <th>start</th>
                <th>end</th>
            </tr>
        </thead>

javascript part 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',
          error: function(e) {
            console.log(e);
          }
      },
      columnDefs: [
       {
         'targets': 0,
         'checkboxes': {
                'selectRow': true
          }
       }
     ],
     select: {
         'style': 'multi'
      },
      paging: true,
      pageLength: 50,

server-side php file 服务器端php文件

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

   if ($searchVar != '') {
     $result = DB::table($table)
               ->where('app_name', 'like', '%'.$searchVar.'%')
               ->orWhere('app_id', 'like', '%'.$searchVar.'%')
               ->orderBy('idx', 'desc')
               ->get();
   } else {
     $result = DB::table($table)
               ->skip($start)
               ->limit($length)
               ->orderBy('idx', 'desc')
               ->get();
   }

   $data = array();

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

      for ($i = 0; $i < count($fields); $i++) {

         if (strpos($fields[$i], 'time')) {
           $sub_array[] = gmdate("Y-m-d", $row->{$fields[$i]});
         } else if ($fields[$i] == 'app_process') {
           $arrProcess = [
               1 => 'ready', 2 => 'go', 3 => 'ing', 4 => 'denial',
               5 => 'retry', 6 => 'reexam', 7 => 'complete', 8 => 'stopped',
               9 => 'expired', 10 => 'valid'
            ];

           foreach ($arrProcess as $key=>$val) {
             if($row->{$fields[$i]} == $key) {
                $sub_array[] = $arrProcess[$key];
             }
           }
         } else if ($fields[$i] == 'script_popup') {
             if ($row->{$fields[$i]} == 'Y') {
               $sub_array[] = 'installed';
             } else {
               $sub_array[] = '-';
             }
         } else if ($fields[$i] == 'custom_etc') {
            if ($row->{$fields[$i]} != '') {
              $sub_array[] .= $row->{$fields[$i]}." custom";
            } else {
              $sub_array[] = '-';
            }
         } else {
            $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);
}

What did I wrong here? 我在这里错了什么? I don't know what to do. 我不知道该怎么办。 Please, someone help me? 拜托,有人帮我吗?

I understand what's wrong. 我知道怎么了 The problem is I didn't know what the 'target' means. 问题是我不知道“目标”是什么意思。 I changed the code below, it works. 我更改了下面的代码,它可以工作。

  $this['fields'] = "idx|app_id|app_name|app_ver|byapps_ver|app_process|script_popup|custom_etc|apps_type|start_time|end_time";

The 'target' needs 'idx', so I added the 'idx' into the fields that I get. “目标”需要“ idx”,因此我在获得的字段中添加了“ idx”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 数据表警告:表 id=DimStatus - 初始化数据表时,第 0 行第 0 列请求未知参数“代码” - DataTables warning: table id=DimStatus - Requested unknown parameter 'Code' for row 0, column 0,when initialize datatable jQuery Datatables请求行&#39;0&#39;列&#39;0&#39;的未知参数&#39;0&#39; - jQuery Datatables Requested unknown parameter '0' for row '0' column '0' 数据表-第0行第0列的请求的未知参数&#39;0&#39; - Datatables - Requested unknown parameter '0' for row 0, column 0 添加复选框列显示错误:“第0行,第0列请求的未知参数&#39;0&#39;” - Adding a checkbox column shows error : “Requested unknown parameter '0' for row 0, column 0” 数据表显示:DataTables 警告:表 id=userdetails - 为第 0 行、第 1 列请求未知参数“1” - Datatable showing :DataTables warning: table id=userdetails - Requested unknown parameter '1' for row 0, column 1 DataTables警告:table id = example - 第1行第1列请求的未知参数“1” - DataTables warning: table id=example - Requested unknown parameter '1' for row 1, column 1 第0行获取请求的未知参数&#39;0&#39;数据表服务器端错误 - Getting Requested unknown parameter '0' for row 0 Error in datatables server side 请求第0行的未知参数“ 5”(jquery数据表) - Requested unknown parameter '5' for row 0 (jquery datatables) 数据表:第1行请求的未知参数“ case” - DataTables: Requested unknown parameter 'case' for row 1 请求jQuery数据表中的第0行的未知参数1 - requested unknown parameter 1 for row 0 in jquery datatable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM