Sorting not working for dynamically generated columns
Sorting not working for dynamically generated columns
Hi,
I am working on a "Table Maintenance" module, where a set of tables names will be displayed in the left pane, and clicking on a table name, all records from that table will displayed in the right pane.
hence i am generating my s dynamically. Also "aoColumns" for DataTable is being generated dynamically:
[code]
for (i = 0; i < listColumnMaintenance.length; i++) {
columnMaintenance = listColumnMaintenance[i];
if (columnMaintenance.IsUpdatable) {
tableHeadersHtml += '' + columnMaintenance.ColumnAlias + '';
}
else {
tableHeadersHtml += '' + columnMaintenance.ColumnAlias + '';
}
aoColumns[i] = { "bSortable": true };
}
[/code]
Finally, I am constructing my DataTable:
[code]
datatableTableData = $('#grdTableData').dataTable({
"aoColumns": aoColumns,
"iDisplayLength": 5,
"bProcessing": true,
"bDestroy": true,
"bRetrieve": true,
"bPaginate": true,
"aaSorting": [[totalNumberOfColumns - 1, 'desc']],
"sPaginationType": "two_button",
"oLanguage": {
"sEmptyTable": "No matching records found"
},
"aaData": JSON.parse(jsonResult),
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
for (columnIndex = 0; columnIndex < totalNumberOfColumns; columnIndex++) {
if ($('th:eq(' + columnIndex + ')').attr('class').indexOf('updatable') >= 0) {
$('td:eq(' + columnIndex + ')', nRow).addClass('updatable');
$('td:eq(' + columnIndex + ')', nRow).addClass('widthAuto');
$('td:eq(' + columnIndex + ')', nRow).addClass('heightAuto');
}
}
return nRow;
}
});
[/code]
Now, when the page is rendered, everything else works fine, but column sorting does not work at all.
Its not adding the "sorting" class to s.
Please help!
I am working on a "Table Maintenance" module, where a set of tables names will be displayed in the left pane, and clicking on a table name, all records from that table will displayed in the right pane.
hence i am generating my s dynamically. Also "aoColumns" for DataTable is being generated dynamically:
[code]
for (i = 0; i < listColumnMaintenance.length; i++) {
columnMaintenance = listColumnMaintenance[i];
if (columnMaintenance.IsUpdatable) {
tableHeadersHtml += '' + columnMaintenance.ColumnAlias + '';
}
else {
tableHeadersHtml += '' + columnMaintenance.ColumnAlias + '';
}
aoColumns[i] = { "bSortable": true };
}
[/code]
Finally, I am constructing my DataTable:
[code]
datatableTableData = $('#grdTableData').dataTable({
"aoColumns": aoColumns,
"iDisplayLength": 5,
"bProcessing": true,
"bDestroy": true,
"bRetrieve": true,
"bPaginate": true,
"aaSorting": [[totalNumberOfColumns - 1, 'desc']],
"sPaginationType": "two_button",
"oLanguage": {
"sEmptyTable": "No matching records found"
},
"aaData": JSON.parse(jsonResult),
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
for (columnIndex = 0; columnIndex < totalNumberOfColumns; columnIndex++) {
if ($('th:eq(' + columnIndex + ')').attr('class').indexOf('updatable') >= 0) {
$('td:eq(' + columnIndex + ')', nRow).addClass('updatable');
$('td:eq(' + columnIndex + ')', nRow).addClass('widthAuto');
$('td:eq(' + columnIndex + ')', nRow).addClass('heightAuto');
}
}
return nRow;
}
});
[/code]
Now, when the page is rendered, everything else works fine, but column sorting does not work at all.
Its not adding the "sorting" class to s.
Please help!
This discussion has been closed.
Replies
Allan
That was indeed the problem. I was not constructing my header properly.
Now it works perfectly fine!
Thanks again.