Using fnServerData if present with sAjaxSource to get remote data

Using fnServerData if present with sAjaxSource to get remote data

jnthnlstrjnthnlstr Posts: 27Questions: 0Answers: 0
edited October 2009 in General
Hello,

I'm using the feature sAjaxSource without sServerSide to allow me to make a one-off GET of a remote JSON file that populates a table. However, the file is not in the correct format, so I have to map it to aaData format before letting the rendering step happen.

I've modified the _fnInitialise function as follows to use the fnServerData option if it is provided in the setup options. I think this is a sensible standard behaviour given that you cannot always control the format of remote data.

[code]
/* if there is an ajax source */
if ( oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide )
{
_fnProcessingDisplay( oSettings, true );
// JRL: added use of fnServerData to get the data if present
var callback = function(json) {
/* Got the data - add it to the table */
for ( var i=0 ; i

Replies

  • jnthnlstrjnthnlstr Posts: 27Questions: 0Answers: 0
    Sorry, didn't mean to post this in "general".
  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    Hi jnthnlstr,

    That's superb - thanks very much indeed for posting your code. Looks like quite an interesting way of approaching this issue. I had always been thinking that there are just so many ways to get data and processing it into something useful for aaData, that the developer using DataTables would just write something around the initialisation object: $.getJSON( 'whatever', null, function(json) { /* processing */; /* init the table */ }; or something like this, but it's an interesting idea to generalise the fnServerData function. I'll consider putting this into future releases of DataTables.

    Regards,
    Allan
  • jnthnlstrjnthnlstr Posts: 27Questions: 0Answers: 0
    Pleasure!
This discussion has been closed.