我正在使用Plugin Datatables,我感到非常困惑。
我定义表格:
GuestDataTable = $('#GuestTable').DataTable( {
"columnDefs": [
{ "title": "Titel", "targets": 0 },
{ "title": "Person", "targets": 1 },
{ "title": "An-/Abgemeldet", "targets": 2 },
{ "title": "Gastgeber", "targets": 3 },
{ "title": "An-/Abmeldedatum", "targets": 4 }
],
data: data,
columns: [
{ data: 'academic_title' },
{ data: 'person' },
{ data: 'participated_logo' },
{ data: 'fullname' },
{ data: 'answer_sent_formatted' }
]
});
稍后我需要清除它并填充新内容,但是它将无法正常工作
GuestDataTable.clear().draw();
GuestDataTable.rows.add([{
"Titel" : "Please",
"Person" : "work",
"An-/Abgemeldet" : "already",
"Gastgeber" : "oh",
"An-/Abmeldedatum" : "please"
}]).draw();
如果我尝试执行此操作,则会收到错误消息:"DataTables warning: table id=GuestTable - Requested unknown parameter 'academic_title' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4"
经过广泛的谷歌搜索之后,我似乎需要某种方式转换字符串,因为在初始化过程中,我告诉表要包含对象。
在这里,我无能为力。有人知道我会怎么做到吗?
答案 0 :(得分:0)
从错误中我想到的是,您必须像下面那样传递参数
GuestDataTable.rows.add([{
"academic_title" : "Please",
"Person" : "work",
"participated_logo" : "already",
"fullname" : "oh",
"Aanswer_sent_formatted" : "please"
}]).draw();
或
根据您的JSON更正数据表列数组属性。见下文
GuestDataTable = $('#GuestTable').DataTable( {
data: data,
columns: [
{ data: 'Titel' },
{ data: 'Person' },
{ data: 'An-/Abgemeldet' },
{ data: 'Gastgeber' },
{ data: 'An-/Abmeldedatum' }
]
});