server side and table initialization

server side and table initialization

nochitanochita Posts: 4Questions: 0Answers: 0
edited January 2010 in General
Hi Allan,
I have some issues with server side pagination. The page used to make a json call and received json which contained the complete entitie, then I transformed the data with javascript and populate the table. Now, I set bServerSide to true and I add the setting sAjaxSource to the table as you show on the examples. So, it gets the data, but I still need to process it. I think the right way to do it is by the fnServerData, but When I add this, the data is not retrieved from the server when the page inits. So, the workaround that I found is to add the fnInitComplete function, and make the json call in there, but the fnServerData is called twice. Is there a way to solve it?
Thanks in advance, Noelia

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi Noelia,

    Could you possibly post your initialisation code please? It sounds like you are on the right track with using fnServerData, but what the problem is will hopefully be clearer with the code.

    Regards,
    Allan
  • nochitanochita Posts: 4Questions: 0Answers: 0
    Hi Allan, thanks for the reply. This is the code:
    [code]
    currentTable = $("#currentagents").dataTable({
    "sDom": "ipfrtl",
    "aoColumns": [null, null, {
    "bSearchable": false,
    "bVisible": false
    }, null, null, {
    "bSearchable" : false,
    "bVisible" : false
    }, ],
    "sPaginationType": "full_numbers",
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": http://localhost:8080/context/my_page,
    "fnServerData": function ( sSource, aaData, fnCallback ) {
    alert('fnServerData');
    transformData(aaData.data);
    }
    });
    [/code]

    and the fnInitComplete:

    [code]
    "fnInitComplete": function (){
    alert('fnInitComplete');
    getDatafromServer();
    }
    [/code]

    The issue is that when I first load the page, using firebug, Im not seing that the server is called unless I add the fnInitComplete (and then the fnServerData is called twice).
    I hope it is clearer now.
    Thanks again,
    Noelia
  • nochitanochita Posts: 4Questions: 0Answers: 0
    Hi again, in the previous code, the sAjaxSource appeared with the html tags. In my code the link is a plain text ("sAjaxSource": http://8080/url/my_page)
    Regards, Noelia
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi Noelia,

    Unless your transformData function is doing the Ajax request/response, then you need to add this in. This example ( http://datatables.net/examples/server_side/post.html ) shows $.ajax() being used to get the data. In the callback function you can then transform your data into the formatting that DataTables requires.

    Regards,
    Allan
  • nochitanochita Posts: 4Questions: 0Answers: 0
    thanks! that was exactly the problem!
This discussion has been closed.