fnRowCallback Being Called on Each Redraw
fnRowCallback Being Called on Each Redraw
JanuszJasinski
Posts: 36Questions: 0Answers: 0
So it seems that fnRowCallback is being called on each redraw. I have a fixed column with complex header setup. For all the non fixed columns, I replace the content with a link (using the contents).
As the table is drawn/redrawn 4 times in total, the first 4 columns of non-fixed columns all contain the data from the first non-fixed column.
If I take out the server side call and put in static code, it seems to work just fine [code] "bServerSide": true,
"sAjaxSource": "data.asp",
"sServerMethod": "POST",[/code]
if I leave that in and take out the FixedColmumn code, it also works fine [code] "fnInitComplete": function () {
new FixedColumns(oTable, {
"iLeftColumns": 3,
"sHeightMatch": "auto"
});
}[/code]
However having them both in means the first column I'm targeting is repeated in the next 3 columns! [code] "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
$('td:eq(3)', nRow).html('' + aData[3] + '').click(function () {
$("#thedialog").attr('src', $(this).next('.dialog').attr("href"));
$("#somediv").dialog({
width: 400,
height: 450,
modal: true,
close: function () {
$("#thedialog").attr('src', "about:blank");
}
});
return false
});
}[/code]
As the table is drawn/redrawn 4 times in total, the first 4 columns of non-fixed columns all contain the data from the first non-fixed column.
If I take out the server side call and put in static code, it seems to work just fine [code] "bServerSide": true,
"sAjaxSource": "data.asp",
"sServerMethod": "POST",[/code]
if I leave that in and take out the FixedColmumn code, it also works fine [code] "fnInitComplete": function () {
new FixedColumns(oTable, {
"iLeftColumns": 3,
"sHeightMatch": "auto"
});
}[/code]
However having them both in means the first column I'm targeting is repeated in the next 3 columns! [code] "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
$('td:eq(3)', nRow).html('' + aData[3] + '').click(function () {
$("#thedialog").attr('src', $(this).next('.dialog').attr("href"));
$("#somediv").dialog({
width: 400,
height: 450,
modal: true,
close: function () {
$("#thedialog").attr('src', "about:blank");
}
});
return false
});
}[/code]
This discussion has been closed.
Replies
Allan
However it seems a similar problem arises when I use this and search/sort the columns as documented here http://datatables.net/forums/discussion/16329/search-alters-data-from-fncreatedrow-function#Item_2
I have a similar issue to Janusz; I am using FixedColumns with a lot of rows, hence I tried to use fnRowCallback but it is called 5 times for each row (I'm guessing once for the table, then once for each split table for the fixed columns). The result is that indexes for each column on subsequent calls, so if I'm wanting to e.g. add a class to columns [5, 6, 7, 10], it ends up adding the class to [5, 6, 7, 8, 9, 10, 11, 12, 13].
So I tried using fnCreatedRow and this seems to work for page one (I'm using pagination), but once I go to page 2, 3, etc. the columns are once again offsetted.
Misc. table options:
[code]
var tableOptions = {
'bProcessing': true, // get data clientside
'sDom': '<"cw-table-top"fTl>rt<"cw-table-btm"ip>',
'aaSorting': [],
'sPaginationType': 'full_numbers',
'bDeferRender': true,
'bSortClasses': false
};
[/code]
Callback: (note: what I'm actually trying to do is pad certain columns to a fixed dec place)
[code]
tableOptions.fnCreatedRow = function( row, data ) {
callbackCount++;
formatCells( row, [5, 6, 7, 10], function(num) { return toDecimalPlaces(num, 4); } );
};
var formatCells = function(row, indexes, formatFunction) {
var cells = $(row).children().filter(function(i) {
return $.inArray(i, indexes) > -1;
});
$.map(cells, function(cell) {
var $cell = $(cell);
$cell.html(formatFunction(parseFloat($cell.html())));
});
};
[/code]
Initialize Fixed Columns:
[code]
tableOptions.fnInitComplete = function () {
new FixedColumns(this, {
'iLeftColumns': 3,
'iLeftWidth': 400,
});
};
tableOptions.sScrollX = '100%';
tableOptions.sScrollXInner = '135%';
tableOptions.bScrollCollapse = true;
[/code]
Any ideas, Allan? Janusz, did you come up with a solution?