Disable Ajax load on first load- degrade gracefully....

Disable Ajax load on first load- degrade gracefully....

rob1rob1 Posts: 1Questions: 0Answers: 0
edited October 2009 in General
First I want to say- beautiful job on the docs and examples (and commenting the code). It's why I went with this option. Javascript is NOT my strong point and it was still easy to get the pipeline version working in a CMS.

OK- the issue. I need the tables to work w/js off. Right now- the page loads the html normally (pulling from the db) and then DataTables loads the same data with a new call to the server and rewrites the table. With- the exact same data. That first page load, I really just need Datatable to format the existing data on the page. Only on the first click to sort/page/filter do I need to move to ajax and serverside processing. Any good hints at how I might tackle this one? I did search- but the closest I found suggests this is a nogo w/out altering the source code (http://datatables.net/forums/comments.php?DiscussionID=450).

That said- bit of a different situation. My general lack of js know-how may be preventing me spotting an easy alternative.

Replies

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

    1. Excellent to hear! Thanks for the kind words.

    2. Very interesting issue. DataTables doesn't really support this at the moment, as it would basically involve taking data from more than one source, and DataTables will only take data from one of the four supported sources and not flip between them during the run. Having said that, it might be worth an experiment to see if this will work (can't promise it will)... Use DataTables to initialise the table as if it were reading it from the DOM (so no sAjaxSource etc), but once that initialisation is done, grab the settings object (from fnSettings() ) and set sAjaxSource and oFeatures.bServerSide as required, and hopefully (...) that will do it.

    One more option, you might use fnServerData to intercept the first XHR that is sent out and return the data that has already been discovered by DataTables from the DOM. Might get a little bit fiddly though.

    If that doesn't help, then I suspect that either a code alteration would be required, or you might have to put up with the extra XHR being used when Javascript is enabled.

    Regards,
    Allan
This discussion has been closed.