'How can I get my custom attribute of a column from jquery datatables on draw.dt function?
I have a custom datatable extends jquery datatables. I have a custom attribute in column which name is like dataType. How can I get value of this custom attribute on draw.dt event of jquery datatable?
Here is my custom datatable extension;
$.fn.customDataTable = function (options) {
var dataTable = table.DataTable({
order: options.order,
rowId: options.rowId,
ajax: options.ajax,
columns: options.columns,
paging: paging,
serverSide: true,
processing: true,
responsive: true,
language: {
url: '/Features/Shared/Component/DataTable/Localization/datatables_tr.json',
oPaginate: {
sFirst: '<i class="fas fa-step-backward"></i>',
sPrevious: '<i class="fas fa-caret-left"></i>',
sNext: '<i class="fas fa-caret-right"></i>',
sLast: '<i class="fas fa-step-forward"></i>'
},
sProcessing: `<i class="fas fa-circle-notch fa-spin fa-3x"></i>`,
},
initComplete: function (settings) {
...
...
},
drawCallback: function () {
...
...
}
});
dataTable.on('draw.dt', function (e) {
...
//Here is where I want to get my custom attribute of a column
...
});
return dataTable;
}
Here is an example usage of my custom datatable;
$('#tbl_Company').customDataTable({
order: [[0, 'desc']],
rowId: 'id',
ajax: {
url: '/Company/GetCompanies',
type: 'POST',
dataType: 'json'
},
columns: [
{
data: 'createdAt',
name: 'CreatedAt',
orderable: false,
defaultContent: '',
dataType: 'date'
}
]
});
Solution 1:[1]
I solved this as below
dataTable.on('draw.dt', function (e) {
dataTable.cells().every(function (r, c) {
var dataType = dataTable.settings()[0].aoColumns[c].dataType;
if (dataType) {
...
}
});
});
thank you @ruleboy21
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aykut Demirci |
