save selection after fnStandingRedraw

save selection after fnStandingRedraw

mbroadstmbroadst Posts: 14Questions: 0Answers: 0
edited October 2011 in General
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

Replies

  • mbroadstmbroadst Posts: 14Questions: 0Answers: 0
    I've been trying to trace down where the problem occurs. Here is what I've discovered:

    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.
  • mbroadstmbroadst Posts: 14Questions: 0Answers: 0
    Well, I've found a temporary solution. If I wrap the section of the code that reapplies the "row_selected" class to the selected rows in a setTimeout (with a timeout of 100ms), then the rows are selected again. The problem at this point is that there is a noticeable "blip" where the rows are shown unselected, and then selected in a blink.

    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.
This discussion has been closed.