Hi
I'm trying to sort out a delete function for records in a table. I have a button assigned to each row that when clicked I want to delete the record in the database (via ajax) and then delete the row.
I've created a module to handle this to which I'm trying to pass the DataTable object from within the drawCallback
but at this point it appears the object is undefined.
Here's the basic initialisation inclduing the drawCallback
. The table loads on the page as expected.
datatableSetup = function () {
oTable = $('.datatable').DataTable({
//other options have been set but removed for brevity
drawCallback: function (oSettings) {
initDeleteRecord();
},
and here's the method it calls (which passes data to a delete module):
initDeleteRecord = function () {
console.log("init delete:", oTable);
datatableDelete.init({
table: oTable,
url: '/productions/',
itemName: 'Production'
})
},
at this point oTable is underfined
In my initialisation if I do this:
init = function () {
datatableSetup();
initDeleteRecord();
},
Where datatableSetup deals with the usual datatable initialisation, calling initDeleteRecord
appears to pass the datatable object as expected but I'm worried this may not always work if there are delays in drawing the table (large data etc) - should I try to restructure this call as a callback?
So, at what point is the datatable object defined
and data available to place events on and be able to pass the datatable object to another module? I'm still learning so may not have the theory right.
Thank