Multiple Tables and AJAX source (table identification)

Multiple Tables and AJAX source (table identification)

DestiaTrafficDestiaTraffic Posts: 4Questions: 0Answers: 0
edited November 2009 in General
Hi!

Excellent Plugin, first of all!

I've created 4 tables (in JQuery UI tabs) with identical settings. Now, they all would need to have content fetched from an AJAX source.

How do I get some sort of an ID of which table I'm creating with
[code]
oTable = $('.dataTable').dataTable( {
[/code]
so that I can go on with

[code]
"sAjaxSource": '/gui_draft/functions/do_table_content_ajax.php?id='+WHAT_TO_PUT_HERE+'&calledfrom=js',
[/code]
and with what function & paeams do I go out to update the content from the sAjaxSource for the individual tables.

Tuomo

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited November 2009
    Hi Tuomo,

    You can use the $.fn.dataTableExt.iApiIndex ( http://datatables.net/development/ ) to change which table the API functions are to be operated on. So for example:

    [code]
    // Use third table
    $.fn.dataTableExt.iApiIndex = 2;

    // Set Ajax source
    oTable.fnSettings().sAjaxSource = "whatever"l
    [/code]
    It might even be best to use the fnReloadAjax() API plug-in. Don't think I've ever tried it with multiple tables, but it should work... :-)

    Regards,
    Allan
  • DestiaTrafficDestiaTraffic Posts: 4Questions: 0Answers: 0
    Thanks!

    Got this to work perfectly.
  • manoharsolanki123manoharsolanki123 Posts: 8Questions: 0Answers: 0
    Hello All,
    Is there a example of how to use this plugin $.fn.dataTableExt.iApiIndex
    I also have a similar problem i.e. I have 2 datatables in a page with different sAjaxSource and both are initialized on load of the page in ready().
    What's happening is that, the result of second comes first and tries to fill in the first table with different columns and hence causing the JSON format error.
    @Allan is there any api as sAjaxManager as the similar is with jQuery?
    It would be great if you provide a link for example of the above.

    Regards,
    Manohar
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I'm not sure that iApiIndex will help in this case, although it is possible depending on what is happening... Can you post your initialisation code please?

    If you want, you can control the Ajax request using the fnServerData callback function: http://datatables.net/usage/callbacks#fnServerData

    Allan
  • manoharsolanki123manoharsolanki123 Posts: 8Questions: 0Answers: 0
    Thanks for your quick reply Allan.
    In this I have created a common jsp i.e. getAjaxData.jsp to handle all calls with different requirements passed on as parameter. This returns JSON formatted output.

    Heres the code
    [code]
    $(document).ready(function() {

    $('#showDepFunding').dataTable({

    "sAjaxSource": "<%=request.getContextPath()%>/common/getAjaxData.jsp?indentSeqId=<%=indentSeqId%>&requirement=GETACCDTLS_DEP",
    /*"oLanguage": {"sProcessing": "Loading data in real time"},*/
    "bProcessing": true,
    "bInfo":false,
    "bFilter":false,
    "bPaginate":false,
    "sScrollY": 200,
    "sScrollX": 900
    });

    $('#showProjFunding').dataTable({

    "sAjaxSource": "<%=request.getContextPath()%>/common/getAjaxData.jsp?indentSeqId=<%=indentSeqId%>&requirement=GETALLPROJS_WITH_ACCDTLS",
    "bInfo":false,
    "bFilter":false,
    "bPaginate":false,
    "sScrollY": 200,
    "sScrollX": 900
    });
    });

    [/code]

    Regards,
    Manohar
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    And basically the issue is that the second called to getAjaxData.jsp is point it's data into the first table? Does the second table then get the first's data? I'm wondering if jQuery is seeing the request going to the same URL and cancelling the first, or something like that. I can't think of any way in which DataTables would have messed up the scoping for this to happen... If you use two different URLs does that work? How about if you use POST rather than the default GET (by using fnServerData to override the default)?

    Allan
This discussion has been closed.