Return correct row index when using aaSorting and pagination.
Return correct row index when using aaSorting and pagination.
I am using DataTables 1.9.4, I cannot upgrade. I am using aaSorting to sort my table on the second column ("aaSorting": [[ 1, "desc" ]]). I am using pagination.
The end result I am trying to achieve is to page to a row with a specific ticker if it is not in the first pages view. I have found many code examples which work, but do not take into account the aaSorting.
First I look for the specific ticker in fnRowcallback. If its not found I set a flag. Then in fnInitComplete if the ticker wasn't found I call a function to find the row its in. And this is where my problem is.
Here is one of many I have tried. I can not even take credit for this little diddy as it is someone else's work.
function findRowIndexUsingString(stringToCheckFor){
var rowIndex = null;
$.each(oTable.fnGetData(), function(i, dtRow) {
$.each(dtRow, function(j, dtCol) {
if (dtCol == stringToCheckFor) {
rowIndex = i;
}
});
});
return rowIndex;
}
This returns the correct rowIndex + 1, but that is the row the data was in before aaSorting. So the ajax results have the ticker I am looking for at row 41, when in fact the ticker is in row 10 when the table is rendered.
I have read, and read and read. Everything I have tried always returns the same results with the row index before aaSorting was applied.
Any help would be greatly appreciated.