Hidden cols and fnRowCallback crash
Hidden cols and fnRowCallback crash
Hey.
I am showing and hideing columns dynamically.
It works great.
I am using fnRowCallback (to decide of a background color for each cell dynamicaly and sum the data at the footer).
It works great as well.
BUT - when I try to use fnRowCallback - when there is a hidden col, the code seem to work in an unwanted way.
It seems like the hidden cols are ignored (instead of it being still at index i, index i is now the next col).
What can I do?
thenks in advanced.
I am showing and hideing columns dynamically.
It works great.
I am using fnRowCallback (to decide of a background color for each cell dynamicaly and sum the data at the footer).
It works great as well.
BUT - when I try to use fnRowCallback - when there is a hidden col, the code seem to work in an unwanted way.
It seems like the hidden cols are ignored (instead of it being still at index i, index i is now the next col).
What can I do?
thenks in advanced.
This discussion has been closed.
Replies
Original misguided response follows:
The important thing is to distinguish between the index of retrieved data and the index of rendered data.
Assuming the variable aData (like in the examples) for the retrieved data, when you have hidden columns, aData[4] will NOT be the same column as 'td:eq(4)'.
I haven't worked out how to make it all more dynamic (DataTables is so deep... there's probably a way that I'm overlooking) but if you manually work out which td:eq(x) you want to target, you can still get up and running.
Because of this if you are accessing the DOM elements, then the indexes will be off by one (or more if you hide more columns) _after_ the column which has been hidden.
So the answer to the question requires another question :-) - it depends what you want to do... do you just want the data - in which case the object parameter passed into fnRowCallback provides this in the second parameter: http://datatables.net/usage/callbacks#fnRowCallback , so do you actually need to TD elements. For the latter you can use the internal function _fnGetTdNodes to get an array of the nodes of the row. Something like var an = this.oApi._fnGetTdNodes( nRow );
Allan
What I did was:
At the function itself I checked for each column if it is hidden (using datatables api).
I sumed every hidden cell - and thus I knew which visible td I need to go to in the curent td (his regular position minus the hidden previos cells).
Beware that I need to sum the hidden cells every time - because I dont need to reduce all of the hidden cells from the position of every cell, but the hidden cells that are before the current cell (If there are 4 hidden cells in positions 2,4,5,6 will get the first cell at position 1, the usualy third cell in position 2 (3 minus 1 hidden cells before him), and the usualy seventh cell will be at position number 3 (7 minus 4 hidden cells before him).
Thenks.