I am using datatable jquery.I want to use Sr_no in data-id of td tag but How to get data of Sr_no.
or you can say that I want particular data from data reponse
I have highlighted in code
$("#fir").dataTable({
"bProcessing": true,
"sAjaxSource": "paid.php",
"sDom": "<'row'<'col-sm-6'l><'col-sm-6'f>r>t<'row'<'col-sm-6'i><'col-sm-6'p>>",
"sPaginationType": "full_numbers",
"aoColumns": [
{"mData": "Sr_no"}, <------ I dont want to add this column in table but I want to use value
{"mData": "Category_Name"},
{"mData": "Vendor_Name"},
{"mData": "date"},
{"mData": "Price"},
{"mData": "Payment_Mode"},
{"mData": "remark"},
{"mData": "edit"},
{"mData": "cancel"}
],
'columnDefs': [
{
'targets': 1,
'createdCell': function (td, cellData, rowData, row, col) {
console.log(row,col);
$(td).attr('data-id',Sr_no); <----------------
}
}
]
});
CodePudding user response:
You can use rowData.Sr_no
to get the value of Sr_no
for each row. Change targets: 1
to
{
'targets': 1,
'createdCell': function (td, cellData, rowData, row, col) {
console.log(row,col);
$(td).attr('data-id', rowData.Sr_no);
}
}