server side processing with client side manipulation

server side processing with client side manipulation

jemisonjemison Posts: 21Questions: 0Answers: 0
edited April 2010 in General
is it possible to do like in this example : http://datatables.net/examples/data_sources/server_side.html
but instead do all the manipulation related to the pagination, on the client side? I don't have to use the database, but when the user click on next or a page, for example, i would call via ajax a webservice with the appropriate parameters, and in the callback function of this call, set the data that datatables will use to redraw the table.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi jemison,

    In order to make use of server-side processing, but have pagination done on the client-side, you can make use of pipelining as shown in this example: http://datatables.net/examples/server_side/pipeline.html . What happens is that DataTables will load more data that is actually needed for the current page, and thus when the user wants to go to the next page, it doesn't need to go to the server to get it. However, whenever a sort or filter is performed it will go to the server and get the results.

    It is worth noting that the pipelining example will cache up to 50 records - so if you have millions of rows in your database, this will still work very will with DataTables. The cache of records will only need to be updated from the server every 5 pages.

    Regards,
    Allan
  • jemisonjemison Posts: 21Questions: 0Answers: 0
    Hi Allan,
    thanks for the quick reply, it's working great, but I neef to make some minor change, I want to be able to change the sAjaxSource after initialization , I think I need to modify and use fnReloadAjax to do that, what do you think?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi jemison,

    Are you using server-side processing or not (bServerSide)? If not, then fnReloadAjax will do the trick nicely for you. If you are then, something like 'oTable.fnSettings().sAjaxSource = ...;' and then calling oTable.fnDraw() would probably do it. But yes, it certainly is possible!

    Regards,
    Allan
  • jemisonjemison Posts: 21Questions: 0Answers: 0
    edited April 2010
    Hi Allan,
    thanks, I think I found a minor bug in the pagination, let's say I have 75 records.
    with iPipe = 5; I can show 50 records until the next request on the server. If I click next until the last page (8), it will display correctly on the last page : showing 71 to 75 of 75 entries. but if click last for example from page 2, it will say: showing 71 to 80 of 75 entries. I'm not sure how to fix that, since I set correctly iTotalRecords and iTotalDisplayRecords to 75 in the json reponse.
    here's a part of my settings
    [code]
    ....
    "sPaginationType": "full_numbers",
    "bJQueryUI": true,
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": /url/index,
    "fnServerData": fnDataTablesPipeline,
    ...
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Oo - sounds interesting... Are you able to reproduce this with my example - or can you link me to something which shows this - or (... :-) ) can you tell me exactly how to modify my example and the steps needed to reproduce this, and I'll take a look.

    Regards,
    Allan
  • jemisonjemison Posts: 21Questions: 0Answers: 0
    here's an implementaion with your example.
    in this case, when I click next until the end, on the last page I got showing 71 to 80 of 75 entries.

    [code]
    var Otable;
    var oCache = { iCacheLower: -1 };
    function fnSetKey( aoData, sKey, mValue )
    {
    for ( var i=0, iLen=aoData.length ; i
  • jemisonjemison Posts: 21Questions: 0Answers: 0
    I had to cut fnFormatDetails,fnOpenClose and the table from the previous post because it was too big. but I think you can manage to reproduce the error.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi jemison,

    Thanks for that - the "for ( $i=0; $i <50; $i++){" line in your server-side script looks a bit suspect - in fact the script as a whole looks a little suspect :-). For example there is no sEcho being returned to DataTables (which while not strictly required, is a very good idea).

    However, what concerns me about the loop, is that even when it should only be returning 25 records (for the second 'get' of data) it will in fact be returning 50. Then DataTables will count the data that is being returned, and display it as needed - however, you've told it that there is only 75 records! I think this disparity is what is causing the problem you are seeing. What I think you need to do is to make your for loop a bit more dynamic, rather than just dumping to much data.

    Possibly one of the scripts from the new server-side development section of the site will help: http://datatables.net/development/server-side/ :-)

    Regards,
    Allan
  • jemisonjemison Posts: 21Questions: 0Answers: 0
    okay, but even after fixing adding sEcho and returning 25 records for the second 'get' I would still get: Showing 71 to 80 of 75 entries, when I click 'Last', something going on with that button.
  • jemisonjemison Posts: 21Questions: 0Answers: 0
    I think that when bNeedServer is true, in fnDataTablesPipeline, the script in not removing the right portion of data with json.aaData.splice( oCache.iDisplayLength, json.aaData.length ); for the last page.
    If I click next, from page 1 to 6 for example, and then ckick last, it would work because bNeedServer is false. for the last page. But if I click last from page 2, then bNeedServer is true, and it would have this:
    json.aaData.splice( iRequestLength, json.aaData.length ) which is json.aaData.splice( 10, 25 );
    and should be json.aaData.splice( 0, 20 )
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi jemison,

    Sorry for the delay in getting back to you. I'm not sure I fully agree about the splice being the problem as I have been unable to reproduce this in my example when clicking on 'last'. Even when altering the number of pages which are cached it doesn't match watch you are seeing. Could you post a link to an example showing this problem please?

    Allan
This discussion has been closed.