Dynamically columns

Dynamically columns

nulelenulele Posts: 1Questions: 0Answers: 0
edited July 2010 in General
Hello,
this is my first message... I only want to share with the forum my personal method to dynamically create columns set.
I just put the columns I need in an array and dynamically create an object containing all columns informations then I pass this object to the aaData property.

var obj;
var aoColumns = [];
var neededColumnsArray = new Array("column1", "column2", ...);

// add needed columns
$.each(neededColumnsArray, function(k, v) {
obj = new Object();
obj.sTitle = v;
obj.sClass = "center";
obj.fnRender = function(obj) {
var sReturn = obj.aData[ obj.iDataColumn ];
... something ...
return sReturn;
}
aoColumns .push(obj);
});

// create the table
$('#dynamic').html( '' );
$('#example').dataTable( {
"aaData": aDataSet,
"aoColumns": aoColumns
});

I hope it could help
Bye

Replies

This discussion has been closed.