【发布时间】:2020-11-18 22:24:16
【问题描述】:
我正在尝试使用 row.add() 在此数据表中添加新行。但后来我得到这个错误:
DataTables 警告:表 id=tblPainAssessChart - 请求第 2 行第 1 列的未知参数“PainSite”。
这是数据表的初始化:
gblPainChartTable = $('#tblPainAssessChart').DataTable({
responsive: true,
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": true,
language: { search: "",
searchPlaceholder: "Search",
sLengthMenu: "_MENU_items"
},
processing: true,
serverSide: true,
ajax: '{!! route('getAjaxPainAssessChartData', ['id' => $T_Patient->id]) !!}',
columns: [
{
render: function(data, type, row, meta) {
data = moment(row.Date, 'YYYY-MM-DD').format('DD/MMM/YYYY');
return data;
}
},
{ data: 'PainSite', name:'PainSite'},
{ data: 'TypeofPain', name: 'TypeofPain'},
{ data: 'PainDegree', name: 'PainDegree'},
{
render: function(data, type, row, meta) {
data = ''
// + '<a onclick="editPA(' + meta.row + ')" class="blue-text btn-edit" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Edit"><i class="fas fa-stop action-icon-img"></i></a>'
// + '<a onclick="removePA(' + meta.row + ')" class="red-text btn-remove" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Remove"><i class="fa fa-times action-icon-img"></i></a>'
// +'';
return data;
}
}
],
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"columnDefs": [
{
"targets": 0, // Date
"className": "text-center"
},
{
"targets": 1, // PainSites
"className": "text-center",
"orderable": false
},
{
"targets": 2, // Type of Pain
"className": "text-center",
"orderable": false
},
{
"targets": 3, // PainDegree
"className": "text-center",
"orderable": false
},
{
"targets": 4, // Action
"className": "text-center",
"orderable": false
},
]
});
这是向数据表添加新行的函数。
function addPA(){
var DatePA = $("#Date").val();
var PainSite = $("#PainSite").val();
var TypeofPain = $("#TypeofPain").val();
var PainDegree = $("#PainDegree").val();
var DatePAF = moment(DatePA).format("DD-MMM-YYYY");
gblPainChartTable.row.add( [
DatePAF,
PainSite,
TypeofPain,
PainDegree,
'<a onclick="editPA(' + lastPANo + ')" class="blue-text btn-edit" data-toggle="tooltip" data-placement="bottom" title="Edit"><i class="fas fa-pencil-alt action-icon-img"></i></a>' +
'<a onclick="removePA(' + lastPANo + ')" class="red-text btn-delete" data-toggle="tooltip" data-placement="bottom" title="Delete"><i class="fas fa-trash action-icon-img"></i></a>'
]).draw();
}
我错过了什么?
编辑:
现在没有显示错误,但仍然没有将新行添加到表中
【问题讨论】: