Scroller should call infoCallback in _fnInfo

Scroller should call infoCallback in _fnInfo

danielku15danielku15 Posts: 6Questions: 1Answers: 0
edited May 2014 in Bug reports

The main DataTables check for an existing infoCallback and call it additionally before actually writing the info to the DOM. The _fnInfo function of the Scroller does not do that. This will cause a flickering in the info panel between the text produced by the callback and the text generated by the Scroller.

[Edit] I created an override/workaround which makes the scroller call the callback:

// Let Scroller call the callback
jQuery.fn.dataTable.Scroller.prototype._fnInfo = (function (old) {
    var tempInfo = $('<div></div>');
    return function () {
        var dt = this.s.dt,
            lang = dt.oLanguage,
            scrollTop = this.dom.scroller.scrollTop,
            start = Math.floor(this.fnPixelsToRow(scrollTop, false, this.s.ani) + 1),
            max = dt.fnRecordsTotal(),
            total = dt.fnRecordsDisplay(),
            possibleEnd = Math.ceil(this.fnPixelsToRow(scrollTop + this.s.heights.viewport, false, this.s.ani)),
            end = total < possibleEnd ? total : possibleEnd,
            out;

        var oldFeature = dt.aanFeatures.i;
        // we simulate another div element
        // to get the generated text without dislaying it
        dt.aanFeatures.i = [tempInfo];

        // generate the info
        old.call(this);
        out = tempInfo.html();

        // call the callback
        var callback = lang.fnInfoCallback;
        if (callback) {
            out = callback.call(dt.oInstance,
               dt, start, end, max, total, out
           );
        }

        // restore the real info features and fill them
        dt.aanFeatures.i = oldFeature;
        var n = dt.aanFeatures.i;
        if (typeof n != 'undefined') {
            for (var i = 0, iLen = n.length ; i < iLen ; i++) {
                $(n[i]).html(out);
            }
        }
    };
})(jQuery.fn.dataTable.Scroller.prototype._fnInfo);

[Edit2] The Scroller should completely override the original DataTable._fnUpdateInfo with its Scroller._fnInfo. The information generated by the original method is completely wrong.
This additional hack makes the DataTable call the Scroller info update function instead of the own.

// call this function with your datatable to replace the original updateInfo
// call with the scroller 
function replaceUpdateInfoCallback(dt) {
    var ctx = dt.context[0];
    for (var i = 0; i < ctx.aoDrawCallback.length; i++) {
        if (ctx.aoDrawCallback[i].fn.name == "_fnUpdateInfo") {
            ctx.aoDrawCallback[i].fn = function (settings) {
                settings.oScroller._fnInfo();
            };
        }   
    }
}
This discussion has been closed.