How to adjust the no.of columns dynamically for datatables
How to adjust the no.of columns dynamically for datatables
nandy_2992
Posts: 3Questions: 1Answers: 0
Hi,
The no.of columns differ for three cases. The datatable is being displayed properly for the first two cases as they have equal no.of columns. But when i try to load for the third case, i get a hazy look, and its displaying 'sWidth undefined' as the no.of columns increases. And the same is happening for the vice-versa.. Could you help me with this? I tried to destroy the datatable but it did not work as i call the same function for three cases in same grid.
Thanks
This discussion has been closed.
Answers
You have to have the correct number of columns in your HTML when you initialise the DataTable, or, if the HTML has no columns, you have to have the correct number of columns in the
columns
array.Allan
I defined the no.of columns for the cases in their own function call. I use same function for generating a datatable through out the application. And when i click for the third case, since the no.of columns increases by 2, the datatable breaks. I get this error only for this scenario as the three cases are being loaded one after another.
I'd need a link to the page to understand what is going wrong. I can only presume that the
columns
array and HTML don't match.Allan
var oTable = $('#'+DT_Array['id']).dataTable({
"bDestroy": true,
"dom": 'Rlfrtip',
"sDom": '<"H"lTfr>t<"F"ip>',
"oTableTools" : {
//"aButtons" : ["copy", "print", "csv", "pdf","xls"],
"aButtons" : ["xls"],
"sSwfPath" : server_path+"/js/TableTools/swf/copy_csv_xls_pdf.swf",
"aButtons": [
{
"sExtends": "xls",
"sFileName": export_file_name+".xls"
}
],
},
This is how i have defined the datatable.
Thanks
Sorry - I'd need to see the page, as I requested above. That will let me trace through the code live to see what is going wrong.
Allan
FYI, not sure if this helps.. but if you're not using server side processing you can actually get pretty dynamic with it by being less specific.
First get your data from database the old fashion~ish way (this example uses a custom class, that I've trimmed a lot of stuff out of.. use your own method to retrieve data):
Next just print the table to HTML in a dynamic way:
And finally just initialize the table: