using the API on table created within ajax call
using the API on table created within ajax call
Im building a table (among other parts of a site) inside of an ajax call.
Everything is working perfectly except that since datatables is called within the success function, I can't reference it with click function later on since the oTable isn't at the global scope.
I found this at stackoverflow explaining how to pass a variable from inside of an ajax success function to the global scope, but it doesn't seem to work when trying to add or remove datatables rows.
Everything is working perfectly except that since datatables is called within the success function, I can't reference it with click function later on since the oTable isn't at the global scope.
I found this at stackoverflow explaining how to pass a variable from inside of an ajax success function to the global scope, but it doesn't seem to work when trying to add or remove datatables rows.
This discussion has been closed.
Replies
[code]
$.getJSON( 'xhr.php', [], function (json) {
$('#example').dataTable( ... );
do_more_stuff();
} );
function do_more_stuff () {
$('#example').dataTable().fnFilter('hello');
// or
var oTable = $('#example').dataTable()
oTable.fnFilter('hello');
}
[/code]
Or you could use a non-locally scoped variable:
[code]
var oTable;
$.getJSON( 'xhr.php', [], function (json) {
oTable = $('#example').dataTable( ... );
do_more_stuff();
} );
function do_more_stuff () {
oTable.fnFilter('hello');
}
[/code]
Allan