Upgrade to ExtJS 3.2.1 - Released 04/27/2010
[extjs.git] / examples / ux / BufferView.js
index 6b826ae..594eb6e 100644 (file)
@@ -1,6 +1,6 @@
 /*!
- * Ext JS Library 3.0.3
- * Copyright(c) 2006-2009 Ext JS, LLC
+ * Ext JS Library 3.2.1
+ * Copyright(c) 2006-2010 Ext JS, Inc.
  * licensing@extjs.com
  * http://www.extjs.com/license
  */
@@ -75,15 +75,15 @@ Ext.ux.grid.BufferView = Ext.extend(Ext.grid.GridView, {
        },
 
        getVisibleRowCount : function(){
-               var rh = this.getCalculatedRowHeight();
-               var visibleHeight = this.scroller.dom.clientHeight;
+               var rh = this.getCalculatedRowHeight(),
+                   visibleHeight = this.scroller.dom.clientHeight;
                return (visibleHeight < 1) ? 0 : Math.ceil(visibleHeight / rh);
        },
 
        getVisibleRows: function(){
-               var count = this.getVisibleRowCount();
-               var sc = this.scroller.dom.scrollTop;
-               var start = (sc == 0 ? 0 : Math.floor(sc/this.getCalculatedRowHeight())-1);
+               var count = this.getVisibleRowCount(),
+                   sc = this.scroller.dom.scrollTop,
+                   start = (sc === 0 ? 0 : Math.floor(sc/this.getCalculatedRowHeight())-1);
                return {
                        first: Math.max(start, 0),
                        last: Math.min(start + count + 2, this.ds.getCount()-1)
@@ -91,25 +91,34 @@ Ext.ux.grid.BufferView = Ext.extend(Ext.grid.GridView, {
        },
 
        doRender : function(cs, rs, ds, startRow, colCount, stripe, onlyBody){
-               var ts = this.templates, ct = ts.cell, rt = ts.row, rb = ts.rowBody, last = colCount-1;
-               var rh = this.getStyleRowHeight();
-               var vr = this.getVisibleRows();
-               var tstyle = 'width:'+this.getTotalWidth()+';height:'+rh+'px;';
-               // buffers
-               var buf = [], cb, c, p = {}, rp = {tstyle: tstyle}, r;
+               var ts = this.templates, 
+            ct = ts.cell, 
+            rt = ts.row, 
+            rb = ts.rowBody, 
+            last = colCount-1,
+                   rh = this.getStyleRowHeight(),
+                   vr = this.getVisibleRows(),
+                   tstyle = 'width:'+this.getTotalWidth()+';height:'+rh+'px;',
+                   // buffers
+                   buf = [], 
+            cb, 
+            c, 
+            p = {}, 
+            rp = {tstyle: tstyle}, 
+            r;
                for (var j = 0, len = rs.length; j < len; j++) {
                        r = rs[j]; cb = [];
-                       var rowIndex = (j+startRow);
-                       var visible = rowIndex >= vr.first && rowIndex <= vr.last;
+                       var rowIndex = (j+startRow),
+                           visible = rowIndex >= vr.first && rowIndex <= vr.last;
                        if (visible) {
                                for (var i = 0; i < colCount; i++) {
                                        c = cs[i];
                                        p.id = c.id;
-                                       p.css = i == 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
+                                       p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
                                        p.attr = p.cellAttr = "";
                                        p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
                                        p.style = c.style;
-                                       if (p.value == undefined || p.value === "") {
+                                       if (p.value === undefined || p.value === "") {
                                                p.value = "&#160;";
                                        }
                                        if (r.dirty && typeof r.modified[c.name] !== 'undefined') {
@@ -119,7 +128,7 @@ Ext.ux.grid.BufferView = Ext.extend(Ext.grid.GridView, {
                                }
                        }
                        var alt = [];
-                       if(stripe && ((rowIndex+1) % 2 == 0)){
+                       if(stripe && ((rowIndex+1) % 2 === 0)){
                            alt[0] = "x-grid3-row-alt";
                        }
                        if(r.dirty){
@@ -167,15 +176,17 @@ Ext.ux.grid.BufferView = Ext.extend(Ext.grid.GridView, {
 
        doUpdate: function(){
                if (this.getVisibleRowCount() > 0) {
-                       var g = this.grid, cm = g.colModel, ds = g.store;
-                       var cs = this.getColumnData();
-
-                       var vr = this.getVisibleRows();
+                       var g = this.grid, 
+                cm = g.colModel, 
+                ds = g.store,
+               cs = this.getColumnData(),
+                       vr = this.getVisibleRows(),
+                row;
                        for (var i = vr.first; i <= vr.last; i++) {
                                // if row is NOT rendered and is visible, render it
-                               if(!this.isRowRendered(i)){
+                               if(!this.isRowRendered(i) && (row = this.getRow(i))){
                                        var html = this.doRender(cs, [ds.getAt(i)], ds, i, cm.getColumnCount(), g.stripeRows, true);
-                                       this.getRow(i).innerHTML = html;
+                                       row.innerHTML = html;
                                }
                        }
                        this.clean();
@@ -211,9 +222,23 @@ Ext.ux.grid.BufferView = Ext.extend(Ext.grid.GridView, {
                        }
                }
        },
+    
+    removeTask: function(name){
+        var task = this[name];
+        if(task && task.cancel){
+            task.cancel();
+            this[name] = null;
+        }
+    },
+    
+    destroy : function(){
+        this.removeTask('cleanTask');
+        this.removeTask('renderTask');  
+        Ext.ux.grid.BufferView.superclass.destroy.call(this);
+    },
 
        layout: function(){
                Ext.ux.grid.BufferView.superclass.layout.call(this);
                this.update();
        }
-});
+});
\ No newline at end of file