save selection after fnStandingRedraw
save selection after fnStandingRedraw
Hello,
I'm trying to save my selection when I call the fnStandingRedraw. The proper indexes are saved, and they are actually reset but shortly after all selections are cleared. Is there a callback that is called after all the drawing has completed? Also, some sort of prototype based approach (like this) would be ideal, as I need this functionality for many different tables in this project.
Here is the code:
[code]
$.fn.dataTableExt.oApi.fnStandingRedraw = function(oSettings) {
// save selection
var selected_indexes = new Array();
$(oSettings.aoData).each(function () {
if ($(this.nTr).hasClass('row_selected')) {
selected_indexes.push(this.nTr.sectionRowIndex);
}
});
if (oSettings.oFeatures.bServerSide === false) {
var before = oSettings._iDisplayStart;
oSettings.oApi._fnReDraw(oSettings);
oSettings._iDisplayStart = before;
oSettings.oApi._fnCalculateEnd(oSettings);
}
//draw the 'current' page
oSettings.oApi._fnDraw(oSettings);
// reapply selected
$(selected_indexes).each(function(index, value) {
$(oSettings.aoData[value].nTr).addClass('row_selected');
});
};
[/code]
Thanks for any advice,
Matt
I'm trying to save my selection when I call the fnStandingRedraw. The proper indexes are saved, and they are actually reset but shortly after all selections are cleared. Is there a callback that is called after all the drawing has completed? Also, some sort of prototype based approach (like this) would be ideal, as I need this functionality for many different tables in this project.
Here is the code:
[code]
$.fn.dataTableExt.oApi.fnStandingRedraw = function(oSettings) {
// save selection
var selected_indexes = new Array();
$(oSettings.aoData).each(function () {
if ($(this.nTr).hasClass('row_selected')) {
selected_indexes.push(this.nTr.sectionRowIndex);
}
});
if (oSettings.oFeatures.bServerSide === false) {
var before = oSettings._iDisplayStart;
oSettings.oApi._fnReDraw(oSettings);
oSettings._iDisplayStart = before;
oSettings.oApi._fnCalculateEnd(oSettings);
}
//draw the 'current' page
oSettings.oApi._fnDraw(oSettings);
// reapply selected
$(selected_indexes).each(function(index, value) {
$(oSettings.aoData[value].nTr).addClass('row_selected');
});
};
[/code]
Thanks for any advice,
Matt
This discussion has been closed.
Replies
1. I placed fnPreDrawCallback and fnDrawCallback calls in my sample DataTable. They simply print out that those callbacks have indeed been called.
2. When the update occurs, I get the following output:
fnPreDrawCallback
setting selected on row: 2
fnPreDrawCallback
fnDrawCallback
This means that the _fnDraw above is only calling the PreDrawCallback, and then returning. I'm starting to think, however, that maybe the code after the _fnDraw is being called too early, not after the completion of the previous method. Is this possible? Otherwise, there is some code somewhere that is calling a full fnDraw even when all I've called is the fnStandingRedraw.
This leads me to think that I need to have a more complicated update mechanism. Is there a way to hook into the code so that I can maintain the row_selected class identifiers in the dataTables code, without having to do it at such a high level?
Either way, I'll keep documenting my progress here, hopefully it can help somebody in the future.