Javascript 如何向Datatable单元格添加数据id
我需要将dataid属性添加到ajaxdatatable的“action”列中,dataid的值应该是从服务器检索到的id 我仍然得到数据属性的未定义值…我做错了什么? 非常感谢你的帮助Javascript 如何向Datatable单元格添加数据id,javascript,jquery,ajax,datatables,Javascript,Jquery,Ajax,Datatables,我需要将dataid属性添加到ajaxdatatable的“action”列中,dataid的值应该是从服务器检索到的id 我仍然得到数据属性的未定义值…我做错了什么? 非常感谢你的帮助 var table = $('#table').DataTable({ "processing": true, //Feature control the processing indicator. "serverSide": true, //Feature control DataTable
var table = $('#table').DataTable({
"processing": true, //Feature control the processing indicator.
"serverSide": true, //Feature control DataTables' server-side processing mode.
"responsive": true,
"autoWidth": false, // Make Datatable really responsive
"order": [[ 0, "asc" ]], //Initial order for registration column.
"stateSave": true, // Save user state
"lengthMenu": [[15, 25, 50, -1], [15, 25, 50, "All"]],
"responsive": true,
"searchHighlight": true,
// Load data for the table's content from an Ajax source
"ajax": {
"url": url + '/ajax_list',
"dataType": "json",
"type": "POST"
},
"columns": [
{ "data": "id" },
{ "data": "contributer" },
{ "data": "images" },
{ "data": "created_at" },
{ "data": "action" },
] ,
//Set column definition initialisation properties.
"columnDefs": [
{
"targets": [ 4 ], //fifth column.
"orderable": false, //set not orderable
"searchable": false, //set not searchable
"createdRow": function ( row, data, index ) {
$( row ).find('td:eq(4)').attr('data-id', '3');
}
}],
dom: "Bfrtip",
buttons: [{
extend: "copy",
className: "btn-sm"
}, {
extend: "csv",
className: "btn-sm"
}, {
extend: "excel",
className: "btn-sm"
}, {
extend: "pdf",
className: "btn-sm"
}, {
extend: "print",
className: "btn-sm"
}],
"language": {
"processing": "Loading. Please wait ..."
},
});
使用而不是createdRow
…使用而不是createdRow
。。。