Show cool things you have done with our products


Post by rule-of-three »

Hi,

This code makes that the locked grid do not jump to start when JSON request happens.

The code works only in Ext Gantt 1.x and Ext JS 3.4.x
        var orig_ganttonLoad = Sch.gantt.GanttView.prototype.onLoad;

        Ext.override(Sch.gantt.GanttView, {
                /*
                 * Override the Sch.gantt.GanttView onLoad method.
                 * The original one in ExtJs 3 "resets the scrollbar" every time new items
                 * are added. This is especially uncomfortable when doing a large, slow,
                 * search.
                 * The original onLoad is now replaced by something which checks if the
                 * scroll position is below the actual bottom grid row. If that's the case,
                 * then and only then we reset the scroll position to the top of the grid.
                 * It is thought that the original scroll-to-the-top behaviour was only
                 * intended to prevent the situation where the user was left with a white
                 * screen when a grid was reloaded with less items than before (- when the
                 * scroll was done).
                 */
                onLoad : function()
                {
                        var rowCount = this.getRows().length;


                        // Count the content hight in pixels.
                        var totalPixels = 0;
                        for(var rowNr=0; rowNr<rowCount; rowNr++) {
                                totalPixels += this.getRow(rowNr).clientHeight;
                        }


                        /*
                         * If the current scroll position is below the bottom of
                         * the grid-items, then scroll all the way up
                         * In theory we could also just move to [bottom - window size] but that
                         * might be confusing.
                         * We let the original onLoad take care of the scrolling: in case it
                         * has other things to do so besides the this.scrollToTop() call.
                         */
                        if (this.el.getScroll().top >= totalPixels) {
                                orig_ganttonLoad.apply(this, arguments);
                        }
                }
        });

Post by Maxim Gorkovsky »

Hello.
Thank you for the contribution!

Post by rule-of-three »

Thanks from the Feedback.

Post Reply