我在DataTables中使用以下代码绘制表格:
projectRevenue = $('#projectRevenue').DataTable({
serverSide: true,
processing: true,
scrollX: true,
stateSave: true,
ajax: {
url: "...",
type: "GET",
dataType: "JSON"
},
columns: [
{ name: 'id', data: 'id' , searchable: false , visible: false },
{ name: 'year', data: 'year' , searchable: true , visible: true , className: "rev_update" },
{ name: 'product_code', data: 'product_code' , searchable: true , visible: true , className: "rev_update" },
{ name: 'jan', data: 'jan' , searchable: true , visible: true , className: "rev_update" },
{ name: 'feb', data: 'feb' , searchable: true , visible: true , className: "rev_update" },
{ name: 'mar', data: 'mar' , searchable: true , visible: true , className: "rev_update" },
{ name: 'apr', data: 'apr' , searchable: true , visible: true , className: "rev_update" },
{ name: 'may', data: 'may' , searchable: true , visible: true , className: "rev_update" },
{ name: 'jun', data: 'jun' , searchable: true , visible: true , className: "rev_update" },
...
为了能够处理数据,我使用此配置为每个td插入了一些属性:
columnDefs: [{
"targets": [1,2,3,4,5,6,7,8,9,10,11,12,13,14],
"createdCell": function (td, cellData, rowData, row, col) {
$(td).attr('contenteditable','true');
$(td).attr('data-id',rowData.id);
}
}],
我想将列的名称添加为属性,但找不到任何方法来获取此数据。所以我想要这样的东西:
$(td).attr('data-id',columns(this).name);
但这是行不通的。
长风秋雁
相关分类