API to set iDisplayStart

API to set iDisplayStart

mikejmikej Posts: 8Questions: 0Answers: 0
edited November 2009 in General
Hi, is there an API function to set which record is displayed first? It can be done by setting iDisplayStart when the table is created but I can't see any way to do it afterwords. Thanks!

More detail that probably doesn't matter:
I am loading the data with sAjaxSource then I am going go scan the data with javaScript and figure out which should be the first record. I think it would be cool if my Ajax call could return more than aaData. I'd like to also do be able to return iDisplayStart (and have it acted on). I suppose, being able to return and set any option would be ideal.

Replies

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi mikej,

    The display start point is actually controlled by a property in the DataTables settings object (_iDisplayStart). Typically I've suggested that people just modify that value and then call fnDraw, but I like having API functions for these kind of things to make it neat and tidy ( :-) ), so I've just bashed together a plug-in API function called fnDisplayStart ( http://datatables.net/plug-ins/api#fnDisplayStart ) which does the messing around with the settings object for you. All you need to do is something like oTable.fnDisplayStart( 10 ); (once the plug-in is installed of course: http://datatables.net/examples/api/plugin_api.html ).

    Regards,
    Allan
  • mikejmikej Posts: 8Questions: 0Answers: 0
    Hey, Allan, that's great you added that function. And its also good to know about those extra functions!
    But I hacked some code before your reply. Actually this works out better for me. I modified jquery.dataTables.js
    so it would accept iDisplayStart returned from the Ajax call:
    [code]
    oSettings.iInitDisplayStart = oSettings._iDisplayStart; // Existing line 1870

    // Added by mikej
    if (json.iDisplayStart !== undefined) {
    oSettings.iInitDisplayStart = json.iDisplayStart;
    }
    [/code]
    This is nice since I don't get two redraws. It means the new data from Ajax is just displayed starting at the right
    place. Rather than the code displaying from record zero then moving to another place based on some javaScript code. (If you see what I mean).
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi mikej,

    Nice one, good to hear you got something that works well for you - hooray for open source :-). Looks like a nice solution you've got there - thanks for sharing.

    Regards,
    Allan
This discussion has been closed.