Using API functions while having more than one Datatable on a page
Using API functions while having more than one Datatable on a page
Hi there,
I have 2 datatables on a page. For the first DT I had to overload the fnReloadAjax(). Now I need to overload this function again for the second DT. but it seems that I can have only one overloaded API function in my page. Could you give me a clue about how to solve this problem?
Thanks in advance,
I have 2 datatables on a page. For the first DT I had to overload the fnReloadAjax(). Now I need to overload this function again for the second DT. but it seems that I can have only one overloaded API function in my page. Could you give me a clue about how to solve this problem?
Thanks in advance,
This discussion has been closed.
Replies
Typically the easiest way to work with multiple DataTables is to simply give each of them an ID and use that reference:
[code]
$('#table1').dataTable().fnReloadAjax();
$('#table2').dataTable().fnReloadAjax( 'myNewSrc' );
[/code]
Allan
[code]
$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource ) {
if ( typeof sNewSource != 'undefined' )
oSettings.sAjaxSource = sNewSource;
console.log($(this));
this.fnClearTable( this );
this.oApi._fnProcessingDisplay( oSettings, true );
var that = this;
var myData = new Array({ "name": "name", "value": reports.root.find('#name').val()}, { "name": "family", "value": reports.root.find('#family').val()}, { "name": "national_id", "value": reports.root.find('#national_id').val()}, { "name": "city", "value": reports.root.find('#city').val()}, { "name": "job", "value": reports.root.find('#job').val()}, { "name": "date_from", "value": reports.root.find('#date_from').val()}, { "name": "date_to", "value": reports.root.find('#date_to').val()}, { "name": "age_from", "value": reports.root.find('#age_from').val()}, { "name": "age_to", "value": reports.root.find('#age_to').val()}, { "name": "credit_from", "value": reports.root.find('#credit_from').val()}, { "name": "credit_to", "value": reports.root.find('#credit_to').val()});
$.ajax({
url: oSettings.sAjaxSource,
dataType: 'json',
data: myData,
type: "POST",
success: function(json) {
/* Got the data - add it to the table */
for ( var i=0 ; i
Allan