[英]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.