Changeset 17

Show
Ignore:
Timestamp:
08/30/08 18:54:41 (4 years ago)
Author:
tsuckowhomberg
Message:
  • fixed: (BufferedStore?.js) store would not allow for adding records without throwing errors when the store was initialized with no records; changed bufferRange to be initialized with [0,0] instead of [0, bufferSize] and incremented bufferRange-count according to the records coming in, until bufferRange[1] equals to bufferSize
  • fixed: (BufferedGridView?.js, BufferedRowSelectionModel?.js) store "add" event would neccessarily trigger the selectionmodel's onAdd-listener before the onAdd-listener of the GridView?, resulting in false rendering of selected records; changed the selection model to listen to the "rowsinserted" event of the view and extended this event to pass the length of added record as the fourth parameter to all it's listeners
  • fixed: (BufferedGridView?.js) collapsed panel would hide added records of the grid when the grid is expanded again and would lose scroll-position; added listener for "expand"-event of the view's gridpanel to recalculate visible rows, the buffer inset and reset the scrollbar's position to the proper value
  • enhancement: (BufferedGridView?.js) improved calculation of rows that would cause spill when new records get added in "insertRows()"
  • fixed: (BufferedGridView?.js) when adding new rows, selected rows which change their position in the view would lose their css-style for indicating that they are selected and pass it to unselected rows; updated "processRows()" to remove css-styles on rows which are currently not selected
  • fixed: (BufferedGridView?.js) "onAdd()" would not always insert records depending on the position they got added in the store; updated and improved code based on "rows get added before first visible row", "rows get added after the last visible row", "rows get added somewhere in between the first and last visible row"
Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/CHANGELOG

    r15 r17  
    1 Version 0.2rc3 
     1Version 0.2rc4 
    2230-August-2008 
    33 
    4 - fixes; 
     4- fixes: 
     5 - BufferedStore.js: store would not allow for adding records without throwing errors when 
     6the store was initialized with no records; changed bufferRange to be initialized with [0,0] 
     7instead of [0, bufferSize] and incremented bufferRange-count according to the records coming 
     8in, until bufferRange[1] equals to bufferSize 
     9 - BufferedGridView.js, BufferedRowSelectionModel.js: store "add" event would neccessarily 
     10trigger the selectionmodel's onAdd-listener before the onAdd-listener of the GridView, resulting 
     11in false rendering of selected records; changed the selection model to listen to the "rowsinserted" 
     12event of the view and extended this event to pass the length of added record as the fourth 
     13parameter to all it's listeners 
     14 - BufferedGridView.js: collapsed panel would hide added records of the grid when the grid is 
     15expanded again and would lose scroll-position; added listener for "expand"-event of the view's 
     16gridpanel to recalculate visible rows, the buffer inset and reset the scrollbar's position to the 
     17proper value 
     18 - BufferedGridView.js: "onAdd()" would not always insert records depending on the position they got 
     19added in the store; updated and improved code based on "rows get added before first visible row", 
     20"rows get added after the last visible row", "rows get added somewhere in between the first and last visible row" 
     21- enhancements: 
     22 - BufferedGridView.js: improved calculation of rows that would cause spill when new records 
     23get added in "insertRows()" 
     24 
     25 
     26Version 0.2rc3 
     2730-August-2008 
     28 
     29- fixes: 
    530 - BufferedGridView.js: last row would not always be rendered proper if the end of 
    631records is reached and the panel would be resized so that more records are displayable 
  • trunk/src/BufferedGridView.js

    r15 r17  
    337337        Ext.ux.grid.BufferedGridView.superclass.init.call(this, grid); 
    338338 
     339        grid.on('expand', this._onExpand, this); 
     340 
    339341        this.ds.on('beforeload', this.onBeforeLoad, this); 
    340342        }, 
     
    463465// {{{ ----------------------dom/mouse listeners-------------------------------- 
    464466 
     467    /** 
     468     * Tells the view to recalculate the number of rows displayable 
     469     * and the buffer inset, when it gets expanded after it has been 
     470     * collapsed. 
     471     * 
     472     */ 
     473    _onExpand : function(panel) 
     474    { 
     475        this.adjustVisibleRows(); 
     476        this.adjustBufferInset(); 
     477        this.adjustScrollerPos(this.rowHeight*this.rowIndex, true); 
     478    }, 
     479 
    465480    // private 
    466481    onColumnMove : function(cm, oldIndex, newIndex) 
     
    766781                this.adjustScrollerPos(this.rowHeight*recordLen, true); 
    767782 
    768                 this.fireEvent("rowsinserted", this, index, index); 
     783                this.fireEvent("rowsinserted", this, index, index, recordLen); 
    769784                this.processRows(); 
    770785                // the cursor did virtually move 
     
    777792 
    778793            this.adjustBufferInset(); 
    779             this.fireEvent("rowsinserted", this, index, index); 
     794            this.fireEvent("rowsinserted", this, index, index, recordLen); 
    780795            return; 
    781796        } 
     
    790805 
    791806        // rows would be added at the end of the rows which are currently 
    792         // displayed, so fire the evnt and return 
    793         if (index >= (this.rowIndex-this.ds.bufferRange[0])+len && len == this.visibleRows) { 
     807        // displayed, so fire the event, resize buffer and adjust visible 
     808        // rows and return 
     809        if (start > this.rowIndex+(this.visibleRows-1)) { 
    794810            this.fireEvent("beforerowsinserted", this, start, end); 
    795             this.fireEvent("rowsinserted", this, start, end); 
     811            this.fireEvent("rowsinserted",       this, start, end, recordLen); 
    796812 
    797813            this.adjustVisibleRows(); 
     
    800816        } 
    801817 
    802         // we are all up in the grid, first row is first record, 
    803         // prepend! 
    804         else if (index == 0 && this.rowIndex == 0) { 
     818        // rows get added somewhere in the current view. 
     819        else if (start >= this.rowIndex && start <= this.rowIndex+(this.visibleRows-1)) { 
    805820            firstRow = index; 
    806             lastRow  = Math.min(end, this.rowIndex+this.visibleRows-1) - this.ds.bufferRange[0]; 
     821            // compute the last row that would be affected of an insert operation 
     822            lastRow  = index+(recordLen-1); 
    807823            this.lastRowIndex  = this.rowIndex; 
    808             this.rowIndex      = 0; 
     824            this.rowIndex      = (start > this.rowIndex) ? this.rowIndex : start; 
     825 
    809826            this.insertRows(ds, firstRow, lastRow); 
     827 
     828            if (this.lastRowIndex != this.rowIndex) { 
     829                this.fireEvent('cursormove', this, this.rowIndex, 
     830                               Math.min(this.ds.totalLength, this.visibleRows-this.rowClipped), 
     831                               this.ds.totalLength); 
     832            } 
    810833 
    811834            this.adjustVisibleRows(); 
     
    813836        } 
    814837 
    815         // rows get added before the first row in the view 
    816         else if (len == this.visibleRows && index <= this.rowIndex-this.ds.bufferRange[0]) { 
    817  
     838        // rows get added before the first visible row, which would not affect any 
     839        // rows to be re-rendered 
     840        else if (start < this.rowIndex) { 
    818841            this.fireEvent("beforerowsinserted", this, start, end); 
    819             this.liveScroller.un('scroll', this.onLiveScroll, this); 
     842 
    820843            this.rowIndex     = this.rowIndex+recordLen; 
    821844            this.lastRowIndex = this.rowIndex; 
     
    826849            this.adjustScrollerPos(this.rowHeight*recordLen, true); 
    827850 
    828             this.fireEvent("rowsinserted", this, start, end); 
    829             this.processRows(); 
     851            this.fireEvent("rowsinserted", this, start, end, recordLen); 
     852            this.processRows(0, undefined, true); 
     853 
    830854            this.fireEvent('cursormove', this, this.rowIndex, 
    831855                           Math.min(this.ds.totalLength, this.visibleRows-this.rowClipped), 
    832856                           this.ds.totalLength); 
    833         } 
    834  
    835         // rows get added somewhere IN the current view 
    836         else if ((len < this.visibleRows ) || index > this.rowIndex-this.ds.bufferRange[0]) { 
    837             firstRow = index; 
    838             lastRow  = Math.min(end, this.rowIndex+this.visibleRows-1) - this.ds.bufferRange[0]; 
    839             this.insertRows(ds, firstRow, lastRow); 
    840  
    841             this.adjustVisibleRows(); 
    842             this.adjustBufferInset(); 
    843  
    844857        } 
    845858 
     
    10531066        var selections = this.grid.selModel.selections; 
    10541067        var ds         = this.ds; 
     1068        var row        = null; 
    10551069        for(var i = startRow, len = rows.length; i < len; i++){ 
    1056             index   = i+cursor; 
    1057             var row = rows[i]; 
     1070            index = i+cursor; 
     1071            row  = rows[i]; 
    10581072            // changed! 
    10591073            row.rowIndex = index; 
     
    10621076                if (this.grid.selModel.bufferedSelections[index] === true) { 
    10631077                    this.addRowClass(i, "x-grid3-row-selected"); 
     1078                } else { 
     1079                    this.removeRowClass(i, "x-grid3-row-selected"); 
    10641080                } 
    10651081                this.fly(row).removeClass("x-grid3-row-over"); 
     
    10991115        // first off, remove the rows at the bottom of the view to match the 
    11001116        // visibleRows value and to not cause any spill in the DOM 
    1101         if (isUpdate !== true && this.getRows().length == this.visibleRows) { 
     1117        if (isUpdate !== true && (this.getRows().length + (lastRow-firstRow)) >= this.visibleRows) { 
    11021118            this.removeRows((this.visibleRows-1)-(lastRow-firstRow), this.visibleRows-1); 
    1103         } 
    1104  
    1105         if (isUpdate) { 
     1119        } else if (isUpdate) { 
    11061120            this.removeRows(viewIndexFirst-this.rowIndex, viewIndexLast-this.rowIndex); 
    11071121        } 
    11081122 
    1109         var html   = this.renderRows(firstRow, lastRow); 
     1123        // compute the range of possible records which could be drawn into the view without 
     1124        // causing any spill 
     1125        var lastRenderRow = (firstRow == lastRow) 
     1126                          ? lastRow 
     1127                          : Math.min(lastRow,  (this.rowIndex-this.ds.bufferRange[0])+(this.visibleRows-1)); 
     1128 
     1129        var html = this.renderRows(firstRow, lastRenderRow); 
    11101130 
    11111131        var before = this.getRow(firstRow-(this.rowIndex-this.ds.bufferRange[0])); 
     
    11191139 
    11201140 
    1121         if (isUpdate === true) { 
     1141        if (!isUpdate === true) { 
    11221142            var rows   = this.getRows(); 
    11231143            var cursor = this.rowIndex; 
     
    11281148 
    11291149        if (!isUpdate) { 
    1130             this.fireEvent("rowsinserted", this, viewIndexFirst, viewIndexLast); 
    1131             this.processRows(); 
     1150            this.fireEvent("rowsinserted", this, viewIndexFirst, viewIndexLast, (viewIndexLast-viewIndexFirst)+1); 
     1151            this.processRows(0, undefined, true); 
    11321152        } 
    11331153    }, 
     
    15211541            if (this.getRows()[0]) { 
    15221542                this.rowHeight = this.getRows()[0].offsetHeight; 
     1543 
     1544                if (this.rowHeight <= 0) { 
     1545                    this.rowHeight = -1; 
     1546                    return; 
     1547                } 
     1548 
    15231549            } else { 
    15241550                return; 
     
    15651591            return; 
    15661592        } 
     1593 
    15671594        // when re-rendering, doe not take the clipped row into account 
    15681595        if (this.rowIndex + (visibleRows-this.rowClipped) > totalLength) { 
  • trunk/src/BufferedRowSelectionModel.js

    r11 r17  
    4545        Ext.ux.grid.BufferedRowSelectionModel.superclass.initEvents.call(this); 
    4646 
    47         this.grid.store.on('add',            this.onAdd,            this); 
     47        this.grid.view.on('rowsinserted',    this.onAdd,            this); 
    4848        this.grid.store.on('selectionsload', this.onSelectionsLoad, this); 
    4949    }, 
     
    129129 
    130130    /** 
    131      * If records where added to the store, this method will work as a callback. 
    132      * The method gets usually called <b>after</b> the onAdd method of the according 
    133      * view was called. 
     131     * If records where added to the store, this method will work as a callback, 
     132     * called by the views' rowsinserted event. 
    134133     * Selections will be shifted down if, and only if, the listeners for the 
    135134     * selectiondirty event will return <tt>true</tt>. 
    136135     * 
    137136     */ 
    138     onAdd : function(store, records, index) 
     137    onAdd : function(store, index, endIndex, recordLength) 
    139138    { 
    140139        var ranges       = this.getPendingSelections(); 
     
    148147            // in the current buffer range will be shifted up! 
    149148            if (rangesLength == 0 && index == Number.MIN_VALUE) { 
    150                 this.shiftSelections(this.grid.getStore().bufferRange[0], records.length); 
    151             } 
    152  
    153             this.fireEvent('selectiondirty', this, index, records.length); 
     149                this.shiftSelections(this.grid.getStore().bufferRange[0], recordLength); 
     150            } 
     151 
     152            this.fireEvent('selectiondirty', this, index, recordLength); 
    154153            return; 
    155154        } 
    156155 
    157156        if (rangesLength == 0) { 
    158             this.shiftSelections(this.grid.getStore().bufferRange[0]+index, records.length); 
     157            this.shiftSelections(index, recordLength); 
    159158            return; 
    160159        } 
     
    165164        var s         = ranges[0]; 
    166165        var e         = ranges[rangesLength-1]; 
    167         var viewIndex = this.grid.getStore().bufferRange[0]+index; 
     166        var viewIndex = index; 
    168167        if (viewIndex <= e || viewIndex <= s) { 
    169             if (this.fireEvent('selectiondirty', this, viewIndex, records.length) !== false) { 
    170                 this.shiftSelections(viewIndex, records.length); 
     168            if (this.fireEvent('selectiondirty', this, viewIndex, recordLength) !== false) { 
     169                this.shiftSelections(viewIndex, recordLength); 
    171170            } 
    172171        } 
  • trunk/src/BufferedStore.js

    r11 r17  
    124124     * @param {Array} 
    125125     */ 
    126     this.bufferRange = [0, this.bufferSize]; 
     126    this.bufferRange = [0, 0]; 
    127127 
    128128    this.on('clear', function (){ 
    129         this.bufferRange = [0, this.bufferSize]; 
     129        this.bufferRange = [0, 0]; 
    130130    }, this); 
    131131 
     
    191191        } 
    192192        this.totalLength += insertRecords.length; 
     193 
     194        // if the store was loaded without data and the bufferRange 
     195        // has to be filled first 
     196        if (this.bufferRange[1] < this.bufferSize) { 
     197            this.bufferRange[1] = Math.min(this.bufferRange[1] + insertRecords.length, this.bufferSize); 
     198        } 
    193199 
    194200        for (var i = 0, len = insertRecords.length; i < len; i++) {