Will the datatable reinitialize inside drawcallback?
Will the datatable reinitialize inside drawcallback?
Hi
I'm trying to create a contextmenu with this plugin: http://swisnl.github.io/jQuery-contextMenu/index.html.
I need to use a the .row function on the very same table that I'm initializing inside the drawCallback. It works if I use the following: table.DataTable().row(this);, but will this reinitialize the table?
When I use table.row(this) I get the following error: Uncaught TypeError: table.row is not a function.
Here's the complete code:
`table.DataTable({
"columns": [
{"data": "id"},
{"data": "name"},
{"data": "created"},
{"data": "modified"},
],
"drawCallback": function () { // Adds contextmenu
jQuery.contextMenu({
selector: 'tbody tr td',
callback: function (key, options) {
var row = table.DataTable().row(this);
doCategoriesContextMenu(row, key);
},
"items": {
"1": {name: "Delete", icon: "delete"}
}
});
},
"pageLength": 10,
"language": {
"lengthMenu": "_MENU_ ",
"search": "",
"loadingRecords": "Loading...",
"processing": "Processing...",
"select-info": ""
},
"columnDefs": [
{
"targets": [0],
"visible": false,
"searchable": false
},
],
"responsive": true,
"select": {
style: 'single'
},
"order": [[0, "asc"]]
});`
Hope someone can help me
Edit: I've no idea why the entire code is not formatted above. I'm using the code formatting option in the editor, but it doesn't work. Hope it's readable.
This question has an accepted answers - jump to answer
Answers
I'm not sure what the variable
table
is but maybe if you change to specifying the table selector it might work. For example:$('#myTable').DataTable().row(this);
Kevin
Thanks for your answer.
The variable table is the my categories table: var table = $('#categories-table').
Your suggestion above works, but that I already knew. My question was if this will initalize the table twice, as the DataTable() function is called twice?
No, you are accessing a new API instance as described here:
https://datatables.net/manual/api#Accessing-the-API
Kevin
Thanks. That's good