Dynamically created last column Average on fnRowCallBack is not Sortable?
Dynamically created last column Average on fnRowCallBack is not Sortable?
iDataTables
Posts: 4Questions: 0Answers: 0
So I use the fnRowCallback event to dynamically calculate and insert the average of the whole row in the last column called Average. The column is defined in the json.aoColumns. However, it is not sortable. Is there anyway to make it sortable? It shows the sort icon but when I click on it it doesn't do anything but changing the sort icon.
[code]"fnRowCallback": function (nRow, aaData, iDisplayIndex, iDisplayIndexFull) {
var iRowTotal = 0;
for (var i = 0; i < aaData.length - 2; i++) {
if (aaData[i + 2] != "")
iRowTotal += parseInt(aaData[i + 2], 10);
}
iRowTotal = parseFloat(iRowTotal / (aaData.length - 3)).toFixed(2);
lastColumn = aaData.length - 1;
$('td:eq(' + lastColumn + ')', nRow).html(iRowTotal);
}[/code]
[code]"fnRowCallback": function (nRow, aaData, iDisplayIndex, iDisplayIndexFull) {
var iRowTotal = 0;
for (var i = 0; i < aaData.length - 2; i++) {
if (aaData[i + 2] != "")
iRowTotal += parseInt(aaData[i + 2], 10);
}
iRowTotal = parseFloat(iRowTotal / (aaData.length - 3)).toFixed(2);
lastColumn = aaData.length - 1;
$('td:eq(' + lastColumn + ')', nRow).html(iRowTotal);
}[/code]
This discussion has been closed.