Switch Json sources from in-memory to ajax

Switch Json sources from in-memory to ajax

richiebogchirichiebogchi Posts: 1Questions: 0Answers: 0
edited July 2013 in DataTables 1.9
Hi,

Is it possible to switch json sources from in-memory (javascript string in json format) to ajax source?

The datatable is initially set as follows (some code altered and omitted for simplicity)
[code]
var oTable = $(tableId).dataTable( {
..
"aaData" : [{"key1" : "value1" , "key2" : "value2" }],
"bServerSide" : false,
..
..
});
[/code]

After such initialization, I need to change the value of bServerSide to true and set the value for sAjaxSource.

I tried two approaches but it did not work. (The ajax call does not fire when i try to sort the tables) :

Approach 1
With the use of fnInitComplete
[code]
var oTable = $(tableId).dataTable( {
..
..
"fnInitComplete": function(oSettings, json) {
oSettings.sAjaxSource = "/ajax-request";
oSettings.bServerSide = true;
}
});
[/code]

Approach 2
Modifying bServerData and sAjaxSource after the datatables block
[code]
var oTable = $(tableId).dataTable( {
..
..
});
oTable.fnSettings().sAjaxSource = "/ajax-request";
oTable.fnSettings().bServerSide = true;
[/code]

Can someone help me with this problem?

Thanks!

Replies

  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    No - you cannot dynamically switch between non-server-side processing and server-side processing. You'd need to destroy and recreate the table.

    Sorry, but the code needed to be able to dynamically enable and disable features would probably add a lot of weight to the core library, which is why it is not available.

    Allan
This discussion has been closed.