Roo/bootstrap/Table.js
[roojs1] / Roo / bootstrap / Table.js
index 68304b5..c990872 100644 (file)
@@ -35,6 +35,7 @@
  * @cfg {Boolean} scrollBody (true|false) default false - body scrolled / fixed header
  * @cfg {Roo.bootstrap.PagingToolbar} footer  a paging toolbar
  * @cfg {Boolean} lazyLoad  auto load data while scrolling to the end (default false)
+ * @cfg {Boolean} auto_hide_footer  auto hide footer if only one page (default false)
  
  * 
  * @constructor
@@ -223,6 +224,10 @@ Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
     
     lazyLoad : false,
     
+    CSS : Roo.util.CSS,
+    
+    auto_hide_footer : false,
+    
     getAutoCreate : function()
     {
         var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
@@ -257,37 +262,25 @@ Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
         }
         
         // this lot should be simplifed...
+        var _t = this;
+        var cp = [
+            'align',
+            'bgcolor',
+            'border',
+            'cellpadding',
+            'cellspacing',
+            'frame',
+            'rules',
+            'sortable',
+            'summary',
+            'width'
+        ].forEach(function(k) {
+            if (_t[k]) {
+                cfg[k] = _t[k];
+            }
+        });
+        
         
-        if (this.align) {
-            cfg.align=this.align;
-        }
-        if (this.bgcolor) {
-            cfg.bgcolor=this.bgcolor;
-        }
-        if (this.border) {
-            cfg.border=this.border;
-        }
-        if (this.cellpadding) {
-            cfg.cellpadding=this.cellpadding;
-        }
-        if (this.cellspacing) {
-            cfg.cellspacing=this.cellspacing;
-        }
-        if (this.frame) {
-            cfg.frame=this.frame;
-        }
-        if (this.rules) {
-            cfg.rules=this.rules;
-        }
-        if (this.sortable) {
-            cfg.sortable=this.sortable;
-        }
-        if (this.summary) {
-            cfg.summary=this.summary;
-        }
-        if (this.width) {
-            cfg.width=this.width;
-        }
         if (this.layout) {
             cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
         }
@@ -323,7 +316,7 @@ Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
         
         this.mainBody = this.el.select('tbody', true).first();
         this.mainHead = this.el.select('thead', true).first();
-        
+        this.mainFoot = this.el.select('tfoot', true).first();
         
         
         
@@ -349,7 +342,9 @@ Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
             }
         } 
         
-        this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
+        if(this.loadMask) {
+            this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
+        }
         
         this.store.on('load', this.onLoad, this);
         this.store.on('beforeload', this.onBeforeLoad, this);
@@ -363,7 +358,7 @@ Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
         
         this.cm.on("headerchange", this.onHeaderChange, this);
         
-        this.cm.on("hiddenchange", this.onHiddenChange, this);
+        this.cm.on("hiddenchange", this.onHiddenChange, this, arguments);
         
     },
     
@@ -587,6 +582,7 @@ Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
             
             var c = {
                 tag: 'th',
+                cls : 'x-hcol-' + i,
                 style : '',
                 html: cm.getColumnHeader(i)
             };
@@ -666,10 +662,6 @@ Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
 
             });
             
-            if(config.hidden){
-                c.cls += ' hidden';
-            }
-            
             header.cn.push(c)
         }
         
@@ -760,6 +752,19 @@ Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
             }, this);
         }
         
+        var tfoot = this.el.select('tfoot', true).first();
+        
+        if(this.footerShow && this.auto_hide_footer && this.mainFoot){
+            
+            this.mainFoot.setVisibilityMode(Roo.Element.DISPLAY).hide();
+            
+            var total = this.ds.getTotalCount();
+            
+            if(this.footer.pageSize < total){
+                this.mainFoot.show();
+            }
+        }
+        
         Roo.each(this.el.select('tbody td', true).elements, function(e){
             e.on('mouseover', _this.onMouseover, _this);
         });
@@ -768,9 +773,6 @@ Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
             e.on('mouseout', _this.onMouseout, _this);
         });
         this.fireEvent('rowsrendered', this);
-        //if(this.loadMask){
-        //    this.maskEl.hide();
-        //}
         
         this.autoSize();
     },
@@ -879,11 +881,11 @@ Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
     
     renderRow : function(cm, ds, rowIndex) 
     {
-        
         var d = ds.getAt(rowIndex);
         
         var row = {
             tag : 'tr',
+            cls : 'x-row-' + rowIndex,
             cn : []
         };
             
@@ -921,7 +923,7 @@ Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
             
             var td = {
                 tag: 'td',
-                cls : rowcfg.rowClass,
+                cls : rowcfg.rowClass + ' x-col-' + i,
                 style: '',
                 html: (typeof(value) === 'object') ? '' : value
             };
@@ -941,6 +943,9 @@ Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
             if(typeof(config.align) != 'undefined' && config.align.length){
                 td.style += ' text-align:' + config.align + ';';
             }
+            if(typeof(config.valign) != 'undefined' && config.valign.length){
+                td.style += ' vertical-align:' + config.valign + ';';
+            }
             
             if(typeof(config.width) != 'undefined'){
                 td.style += ' width:' +  config.width + 'px;';
@@ -968,7 +973,7 @@ Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
                 td.cls += ' col-' + size + '-' + config[size];
 
             });
-             
+            
             row.cn.push(td);
            
         }
@@ -983,13 +988,7 @@ Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
     
     onBeforeLoad : function()
     {
-        //Roo.log('ds onBeforeLoad');
-        
-        //this.clear();
         
-        //if(this.loadMask){
-        //    this.maskEl.show();
-        //}
     },
      /**
      * Remove all rows
@@ -1134,7 +1133,6 @@ Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
     
     onHeaderChange : function()
     {
-        
         var header = this.renderHeader();
         var table = this.el.select('table', true).first();
         
@@ -1142,11 +1140,89 @@ Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
         this.mainHead = table.createChild(header, this.mainBody, false);
     },
     
-    onHiddenChange : function()
+    onHiddenChange : function(colModel, colIndex, hidden)
     {
+        var thSelector = '#' + this.id + ' .x-hcol-' + colIndex;
+        var tdSelector = '#' + this.id + ' .x-col-' + colIndex;
+        
+        this.CSS.updateRule(thSelector, "display", "");
+        this.CSS.updateRule(tdSelector, "display", "");
+        
+        if(hidden){
+            this.CSS.updateRule(thSelector, "display", "none");
+            this.CSS.updateRule(tdSelector, "display", "none");
+        }
+        
         this.onHeaderChange();
-    }
+        this.onLoad();
+    },
     
+    setColumnWidth: function(col_index, width)
+    {
+        // width = "md-2 xs-2..."
+        if(!this.colModel.config[col_index]) {
+            return;
+        }
+        
+        var w = width.split(" ");
+        
+        var rows = this.el.dom.getElementsByClassName("x-col-"+col_index);
+        
+        var h_row = this.el.dom.getElementsByClassName("x-hcol-"+col_index);
+        
+        
+        for(var j = 0; j < w.length; j++) {
+            
+            if(!w[j]) {
+                continue;
+            }
+            
+            var size_cls = w[j].split("-");
+            
+            if(!Number.isInteger(size_cls[1] * 1)) {
+                continue;
+            }
+            
+            if(!this.colModel.config[col_index][size_cls[0]]) {
+                continue;
+            }
+            
+            if(!h_row[0].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
+                continue;
+            }
+            
+            h_row[0].classList.replace(
+                "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
+                "col-"+size_cls[0]+"-"+size_cls[1]
+            );
+            
+        }
+        
+        for(var i = 0; i < rows.length; i++) {
+            
+            for(var j = 0; j < w.length; j++) {
+                
+                var size_cls = w[j].split("-");
+                
+                if(!Number.isInteger(size_cls[1] * 1)) {
+                    continue;
+                }
+                
+                if(!this.colModel.config[col_index][size_cls[0]]) {
+                    continue;
+                }
+                
+                if(!rows[i].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
+                    continue;
+                }
+                
+                rows[i].classList.replace(
+                    "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
+                    "col-"+size_cls[0]+"-"+size_cls[1]
+                );
+            }
+        }
+    }
 });