Passing variable to aoColumns

Passing variable to aoColumns

LesGLesG Posts: 14Questions: 0Answers: 0
edited July 2012 in General
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]

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Try using it not as a string, but as a JSON object:

    [code]
    columns = [{"sClass": "left" }, {"sClass": "left" },{"sClass": "left" }];
    [/code]

    :-)

    Allan
  • LesGLesG Posts: 14Questions: 0Answers: 0
    Thanks for the quick response. Can you provide an example of the json fomat? I've tried several with no luck.
This discussion has been closed.