fnGetNotes(int) perforamance
fnGetNotes(int) perforamance
Hi Allan,
I have profiled my interaction with dataTables and my code on IE7 which is considerably lower than Firefox and Safari 5 and Chrome, and would like to ask if there's an alternative way to the following.
[code]
var index = table.fnAddData(row, false);
var tr = table.fnGetNodes(index);
[/code]
I have realized that if these two lines of code are contained within a loop, then the _fnNoteToDataIndex ( which is called from fnGetNodes) has a big execution time. Is there an alternative way so that when I add a row to the table to be able to retrieve that tr element almost without any additional delay?
Thanks
I have profiled my interaction with dataTables and my code on IE7 which is considerably lower than Firefox and Safari 5 and Chrome, and would like to ask if there's an alternative way to the following.
[code]
var index = table.fnAddData(row, false);
var tr = table.fnGetNodes(index);
[/code]
I have realized that if these two lines of code are contained within a loop, then the _fnNoteToDataIndex ( which is called from fnGetNodes) has a big execution time. Is there an alternative way so that when I add a row to the table to be able to retrieve that tr element almost without any additional delay?
Thanks
This discussion has been closed.
Replies
[code]
var index = table.fnAddData(row, false);
var tr = table.fnGetNodes(index[0]);
[/code]
That is basically the same as:
[code]
var index = table.fnAddData(row, false);
var tr = table.fnSettings().aoData[index[0]];
[/code]
Also, unless I'm missing something - I don't actually see where fnGetNodes is calling _fnNodeToDataIndex(). That function is only called from fnDeleteRow, fnGetData, fnGetPosition and _fnNodeToDataIndex.
Regards,
Allan
_fnNodeToDataIndex is not called from fnGetNodes actually. It was from fnUpdate.
[code]
var iRow = (typeof mRow == 'object') ?
_fnNodeToDataIndex(oSettings, mRow) : mRow;
[/code]
there's no faster way for this is there?
if i do , fnGetNodes(index) does not fail. Whereas the correct would be fnGetNodes(index[0]).
This puzzles me. Any idea why?
Thanks
Andreas
1. Speed of _fnNodeToDataIndex - I can't think of a faster way to do this off the top of my head. I suppose one optimisation would be to check if the node is in the visible range (which would make it return with 10, by default, iterations around the loop if it matches). This is probably a fair optimisation to make since the passed node is far more likely to be visible than not. I'll look at adding this in.
2. fnGetNodes with array as an index - I've no idea why this doesn't fail! I guess the returned value might be null or undefined...
Regards,
Allan
Thanks for your quick replies.
I have thought of caching index[0] returned by fnAddData as map with the key being the row's id. So whenever I have an update on that row, then I could simply get the index via :
[code]
var indices = table.fnAddData(row_array, false);
var index = indices[0];
map[row_id] = index;
--------------
var index = map[row_id]
table.fnUpdate(row_array, index, null, false);
[/code]