Using API functions while having more than one Datatable on a page

Using API functions while having more than one Datatable on a page

aryanetaryanet Posts: 3Questions: 0Answers: 0
edited August 2012 in General
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,

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    By overloading, do you mean you've added extra parameters to the method, or simply that you are calling it with a source / callback set?

    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
  • aryanetaryanet Posts: 3Questions: 0Answers: 0
    Well, to clarify my mean; I have the following code for fnReloadAjax() function:
    [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
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Do you mean you want multiple different fnReloadAjax methods? The one above for one table, and another for other tables? API methods are shared between tables - if you want different methods, just give them different names - fnReloadAjax2 for example.

    Allan
  • aryanetaryanet Posts: 3Questions: 0Answers: 0
    Thanks Allan! it's now working like I was expected. :)
This discussion has been closed.