Passing variable to aoColumns
Passing variable to aoColumns
I'm initializing datatables in a function and need to pass in the column data. I've tried using a json string, but it's not working. Any ideas?
where columns = '[{"sClass": "left" }, {"sClass": "left" },{"sClass": "left" }]';
[code]
function loadDataTable(params, columns){
oTable = jQuery('#siteDetail').dataTable( {
"bProcessing": false,
"bServerSide": false,
"sAjaxSource": 'View/Data/DetailDataSite.cfc?method=getdetaildata_json',
"bAutoWidth": false,
"bFilter": false,
"bInfo": true,
"bJQueryUI": false,
"bPaginate": true,
"bFilter": true,
"sPaginationType": "four_button",
"bSort": false,
"iDisplayLength": 25,
"aLengthMenu": [[25, 50, 75, 100], [25, 50, 75, 100]],
"bDeferRender": true,
"sDom": '<"top"lfip<"clear">>rt<"bottom"<"#spacer">ip<"clear">>',
"aoColumns": columns,
fnServerData: function ( sSource, aoData, fnDraw ) {
for (i=1; i<=2; i++){
prevPage = i-1;
if(i > 1){
params = params.replace('PAGENUM=' + prevPage, 'PAGENUM=' + i);
}
jQuery.ajax({
error: function(XMLHttpRequest, textStatus, errorThrown){alert(errorThrown)},
"dataType": "json",
"type": "POST",
"url": sSource,
"data": params,
"success": function(resp){
fnDraw(resp);
}
});
}
}
} );
setTimeout("sortTable()", 5000);
}
[/code]
where columns = '[{"sClass": "left" }, {"sClass": "left" },{"sClass": "left" }]';
[code]
function loadDataTable(params, columns){
oTable = jQuery('#siteDetail').dataTable( {
"bProcessing": false,
"bServerSide": false,
"sAjaxSource": 'View/Data/DetailDataSite.cfc?method=getdetaildata_json',
"bAutoWidth": false,
"bFilter": false,
"bInfo": true,
"bJQueryUI": false,
"bPaginate": true,
"bFilter": true,
"sPaginationType": "four_button",
"bSort": false,
"iDisplayLength": 25,
"aLengthMenu": [[25, 50, 75, 100], [25, 50, 75, 100]],
"bDeferRender": true,
"sDom": '<"top"lfip<"clear">>rt<"bottom"<"#spacer">ip<"clear">>',
"aoColumns": columns,
fnServerData: function ( sSource, aoData, fnDraw ) {
for (i=1; i<=2; i++){
prevPage = i-1;
if(i > 1){
params = params.replace('PAGENUM=' + prevPage, 'PAGENUM=' + i);
}
jQuery.ajax({
error: function(XMLHttpRequest, textStatus, errorThrown){alert(errorThrown)},
"dataType": "json",
"type": "POST",
"url": sSource,
"data": params,
"success": function(resp){
fnDraw(resp);
}
});
}
}
} );
setTimeout("sortTable()", 5000);
}
[/code]
This discussion has been closed.
Replies
[code]
columns = [{"sClass": "left" }, {"sClass": "left" },{"sClass": "left" }];
[/code]
:-)
Allan