fnDrawCallback function which accepts a callback itself
fnDrawCallback function which accepts a callback itself
joelones
Posts: 7Questions: 1Answers: 0
I have the following:
[code]
var oTable = $('#patient_table').dataTable( {
....
"fnDrawCallback": loadModalLinks,
});
[/code]
loadModalLinks is defined in another js file which is included, loadModalLinks also takes in a callback function via the first argument, how would you write this? I'm also using jquery.
As the following does not work:
[code]
...
"fnDrawCallback": loadModalLinks(function () {})
[/code]
[code]
var oTable = $('#patient_table').dataTable( {
....
"fnDrawCallback": loadModalLinks,
});
[/code]
loadModalLinks is defined in another js file which is included, loadModalLinks also takes in a callback function via the first argument, how would you write this? I'm also using jquery.
As the following does not work:
[code]
...
"fnDrawCallback": loadModalLinks(function () {})
[/code]
This discussion has been closed.
Replies
fnDrawCallback: function () {
loadModalLinks( function ... );
}
[/code]
Before you were executing the function and assigning its return value to the draw callback.
> I'm also using jquery.
I hope so! DataTables is a jQuery plug-in after all :-)
Allan
[code]
"fnDrawCallback": function () {
loadModalLinks(function() { console.log('test')} );
}
[/code]
where:
[code]
function loadModalLinks(fnCallback) {
....
if ( typeof fnCallback == 'function' && fnCallback !== null ) { fnCallback(); }
...
}
[/code]
The error i get is:
[quote]
Uncaught TypeError: Object [object global] has no method 'getAttribute'
[/quote]
what am i missing?
Allan
[code]
function loadModalLinks(fnCallback) {
return function() {
....
$.post(url, function(data) {
if (data.success){
oTable.fnDraw(false);
if ( typeof fnCallback == 'function' && fnCallback !== null ) {
....
};
}
[/code]
[code]
"fnDrawCallback": loadModalLinks(function() {
console.log('fnCallback code');
}),
[/code]
The whole point was to execute loadModalLinks function and run the fnCallback if the post was successfully, in this case the console.log('fnCallback code');
still not sure why this works now