There is one very complicated workaround based on column hashing.
Follow these steps to initialize the table. First define "aoColumns": with four columns:
"aoColumns": [ { "sTitle": "Id", "mData": "id" }, { "sTitle": "Label" "mData": "label" }, { "sTitle": "Type", "mData": "type" }, { "sTitle": "Name" ,"mData": "name" }]
Then define the ajax source, for example, for the first switch case:
"sAjaxSource" : "/getFirstAjaxSource";
After initializing the table, set the 3 and 4 columns (in your case, βTypeβ and βNameβ) as invisible using jQuery, so you will only see the first and second columns:
$(function(){ oTable.fnSetColumnVis( 2, false); oTable.fnSetColumnVis( 3, false ); })
Then, the following logic is used in the click handler functions.
First button:
jQuery('#first').live('click',function () { oTable.fnSettings().sAjaxSource = "/getFirstAjaxSource"; oTable.fnSetColumnVis( 0, true); oTable.fnSetColumnVis( 1, true ); oTable.fnSetColumnVis( 2, false); oTable.fnSetColumnVis( 3, false ); });
Second button:
jQuery('#second').live('click',function () { oTable.fnSettings().sAjaxSource = "/getSecondAjaxSource"; oTable.fnSetColumnVis( 0, false); oTable.fnSetColumnVis( 1, false ); oTable.fnSetColumnVis( 2, true); oTable.fnSetColumnVis( 3, true ); });
Remember to add fake values ββfor hidden columns in the ajax source.