Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
395
A slightly nicer Row.getIndex for virtual mode
posted

I traced a few instabilities in the way Virtual mode operates to the igtbl_Row's getIndex method in the JavaScript. In Virtual mode, the code uses the scroll bar position to determine the top item, but if you are using your own Ajax calls, the scroll bar position may not be a reliable indicator of the first row.

In any case, there is a better indicator of the first row: the index of the first row itself. Here's a substitution function I wrote for it:

function overrideRowGetIndex() {
            igtbl_Row.prototype["getIndex"] =
            function(virtual) {
                if (this.Node) {
                    var index = igtbl_parseInt(this.Node.getAttribute("i"));
                    var g = this.Band.Grid;
                    if (this.Band.Index == 0 && !virtual && g.XmlLoadOnDemandType == 2) {
                        var firstRow = g.Rows.getRow(0);
                        if (firstRow) {
                            var firstIndex = igtbl_parseInt(firstRow.Node.getAttribute("i"));
                            index -= firstIndex; // Just subtract the index of the first row
                        }
                    }
                    return index;
                }
                else if (this.OwnerCollection)
                    return this.OwnerCollection.indexOf(this);
                return -1;
            }
        }

You can add an else index = -1; on that if (firstRow) if you care to. Call it near the end of your .aspx so that the Infragistics JavaScript is already registered:

    <script type="text/javascript">overrideRowGetIndex();</script>

I found this approach made things a *lot* stabler in the sometimes hard-to-understand Virtual mode. No more "surprise! the index for this row is -14!" or round-off-induced off-by-one errors for me :)

-- Ritchie Annand

Parents
  • 24671
    Verified Answer
    posted

     Hi Ritchie,

    This is really great feedback ! Thanks very much , I have forwarded your comments to the development team and we will try to evaluate and incorporate these improvements as soon as possible. 

    Thanks,

    Angel 

Reply Children
No Data