8da0d8a9288d452ec5e20f026d723970250190db
[roojs1] / Roo / bootstrap / Table.js
1 /**
2  * @class Roo.bootstrap.Table
3  * @licence LGBL
4  * @extends Roo.bootstrap.Component
5  * @children Roo.bootstrap.TableBody
6  * Bootstrap Table class.  This class represents the primary interface of a component based grid control.
7  * Similar to Roo.grid.Grid
8  * <pre><code>
9  var table = Roo.factory({
10     xtype : 'Table',
11     xns : Roo.bootstrap,
12     autoSizeColumns: true,
13     
14     
15     store : {
16         xtype : 'Store',
17         xns : Roo.data,
18         remoteSort : true,
19         sortInfo : { direction : 'ASC', field: 'name' },
20         proxy : {
21            xtype : 'HttpProxy',
22            xns : Roo.data,
23            method : 'GET',
24            url : 'https://example.com/some.data.url.json'
25         },
26         reader : {
27            xtype : 'JsonReader',
28            xns : Roo.data,
29            fields : [ 'id', 'name', whatever' ],
30            id : 'id',
31            root : 'data'
32         }
33     },
34     cm : [
35         {
36             xtype : 'ColumnModel',
37             xns : Roo.grid,
38             align : 'center',
39             cursor : 'pointer',
40             dataIndex : 'is_in_group',
41             header : "Name",
42             sortable : true,
43             renderer : function(v, x , r) {  
44             
45                 return String.format("{0}", v)
46             }
47             width : 3
48         } // more columns..
49     ],
50     selModel : {
51         xtype : 'RowSelectionModel',
52         xns : Roo.bootstrap.Table
53         // you can add listeners to catch selection change here....
54     }
55      
56
57  });
58  // set any options
59  grid.render(Roo.get("some-div"));
60 </code></pre>
61
62 Currently the Table  uses multiple headers to try and handle XL / Medium etc... styling
63
64
65
66  *
67  * @cfg {Roo.grid.AbstractSelectionModel} sm The selection model to use (cell selection is not supported yet)
68  * @cfg {Roo.data.Store} store The data store to use
69  * @cfg {Roo.grid.ColumnModel} cm[] A column for the grid.
70  * 
71  * @cfg {String} cls table class
72  *
73  *
74  * @cfg {string} empty_results  Text to display for no results 
75  * @cfg {boolean} striped Should the rows be alternative striped
76  * @cfg {boolean} bordered Add borders to the table
77  * @cfg {boolean} hover Add hover highlighting
78  * @cfg {boolean} condensed Format condensed
79  * @cfg {boolean} responsive default false - if this is on, columns are rendered with col-xs-4 etc. classes, otherwise columns will be sized by CSS,
80  *                also adds table-responsive (see bootstrap docs for details)
81  * @cfg {Boolean} loadMask (true|false) default false
82  * @cfg {Boolean} footerShow (true|false) generate tfoot, default true
83  * @cfg {Boolean} summaryFooterShow (true|false) generate tfoot for summary, default false
84  * @cfg {Boolean} headerShow (true|false) generate thead, default true
85  * @cfg {Boolean} rowSelection (true|false) default false
86  * @cfg {Boolean} cellSelection (true|false) default false
87  * @cfg {Boolean} scrollBody (true|false) default false - body scrolled / fixed header (with resizable columns)
88  * @cfg {Roo.bootstrap.PagingToolbar} footer  a paging toolbar
89  * @cfg {Boolean} lazyLoad  auto load data while scrolling to the end (default false)
90  * @cfg {Boolean} auto_hide_footer  auto hide footer if only one page (default false)
91  * @cfg {Boolean} enableColumnResize default true if columns can be resized = needs scrollBody to be set to work (drag/drop)
92  * @cfg {Boolean} disableAutoSize disable autoSize() and initCSS()
93  *
94  * 
95  * @cfg {Number} minColumnWidth default 50 pixels minimum column width 
96  * 
97  * @constructor
98  * Create a new Table
99  * @param {Object} config The config object
100  */
101
102 Roo.bootstrap.Table = function(config)
103 {
104     Roo.bootstrap.Table.superclass.constructor.call(this, config);
105      
106     // BC...
107     this.rowSelection = (typeof(config.rowSelection) != 'undefined') ? config.rowSelection : this.rowSelection;
108     this.cellSelection = (typeof(config.cellSelection) != 'undefined') ? config.cellSelection : this.cellSelection;
109     this.headerShow = (typeof(config.thead) != 'undefined') ? config.thead : this.headerShow;
110     this.footerShow = (typeof(config.tfoot) != 'undefined') ? config.tfoot : this.footerShow;
111     
112     this.view = this; // compat with grid.
113     
114     this.sm = this.sm || {xtype: 'RowSelectionModel'};
115     if (this.sm) {
116         this.sm.grid = this;
117         this.selModel = Roo.factory(this.sm, Roo.grid);
118         this.sm = this.selModel;
119         this.sm.xmodule = this.xmodule || false;
120     }
121     
122     if (this.cm && typeof(this.cm.config) == 'undefined') {
123         this.colModel = new Roo.grid.ColumnModel(this.cm);
124         this.cm = this.colModel;
125         this.cm.xmodule = this.xmodule || false;
126     }
127     if (this.store) {
128         this.store= Roo.factory(this.store, Roo.data);
129         this.ds = this.store;
130         this.ds.xmodule = this.xmodule || false;
131          
132     }
133     if (this.footer && this.store) {
134         this.footer.dataSource = this.ds;
135         this.footer = Roo.factory(this.footer);
136     }
137     
138     /** @private */
139     this.addEvents({
140         /**
141          * @event cellclick
142          * Fires when a cell is clicked
143          * @param {Roo.bootstrap.Table} this
144          * @param {Roo.Element} el
145          * @param {Number} rowIndex
146          * @param {Number} columnIndex
147          * @param {Roo.EventObject} e
148          */
149         "cellclick" : true,
150         /**
151          * @event celldblclick
152          * Fires when a cell is double clicked
153          * @param {Roo.bootstrap.Table} this
154          * @param {Roo.Element} el
155          * @param {Number} rowIndex
156          * @param {Number} columnIndex
157          * @param {Roo.EventObject} e
158          */
159         "celldblclick" : true,
160         /**
161          * @event rowclick
162          * Fires when a row is clicked
163          * @param {Roo.bootstrap.Table} this
164          * @param {Roo.Element} el
165          * @param {Number} rowIndex
166          * @param {Roo.EventObject} e
167          */
168         "rowclick" : true,
169         /**
170          * @event rowdblclick
171          * Fires when a row is double clicked
172          * @param {Roo.bootstrap.Table} this
173          * @param {Roo.Element} el
174          * @param {Number} rowIndex
175          * @param {Roo.EventObject} e
176          */
177         "rowdblclick" : true,
178         /**
179          * @event mouseover
180          * Fires when a mouseover occur
181          * @param {Roo.bootstrap.Table} this
182          * @param {Roo.Element} el
183          * @param {Number} rowIndex
184          * @param {Number} columnIndex
185          * @param {Roo.EventObject} e
186          */
187         "mouseover" : true,
188         /**
189          * @event mouseout
190          * Fires when a mouseout occur
191          * @param {Roo.bootstrap.Table} this
192          * @param {Roo.Element} el
193          * @param {Number} rowIndex
194          * @param {Number} columnIndex
195          * @param {Roo.EventObject} e
196          */
197         "mouseout" : true,
198         /**
199          * @event rowclass
200          * Fires when a row is rendered, so you can change add a style to it.
201          * @param {Roo.bootstrap.Table} this
202          * @param {Object} rowcfg   contains record  rowIndex colIndex and rowClass - set rowClass to add a style.
203          */
204         'rowclass' : true,
205           /**
206          * @event rowsrendered
207          * Fires when all the  rows have been rendered
208          * @param {Roo.bootstrap.Table} this
209          */
210         'rowsrendered' : true,
211         /**
212          * @event contextmenu
213          * The raw contextmenu event for the entire grid.
214          * @param {Roo.EventObject} e
215          */
216         "contextmenu" : true,
217         /**
218          * @event rowcontextmenu
219          * Fires when a row is right clicked
220          * @param {Roo.bootstrap.Table} this
221          * @param {Number} rowIndex
222          * @param {Roo.EventObject} e
223          */
224         "rowcontextmenu" : true,
225         /**
226          * @event cellcontextmenu
227          * Fires when a cell is right clicked
228          * @param {Roo.bootstrap.Table} this
229          * @param {Number} rowIndex
230          * @param {Number} cellIndex
231          * @param {Roo.EventObject} e
232          */
233          "cellcontextmenu" : true,
234          /**
235          * @event headercontextmenu
236          * Fires when a header is right clicked
237          * @param {Roo.bootstrap.Table} this
238          * @param {Number} columnIndex
239          * @param {Roo.EventObject} e
240          */
241         "headercontextmenu" : true,
242         /**
243          * @event mousedown
244          * The raw mousedown event for the entire grid.
245          * @param {Roo.EventObject} e
246          */
247         "mousedown" : true
248         
249     });
250 };
251
252 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
253     
254     cls: false,
255     
256     empty_results : '',
257     striped : false,
258     scrollBody : false,
259     bordered: false,
260     hover:  false,
261     condensed : false,
262     responsive : false,
263     sm : false,
264     cm : false,
265     store : false,
266     loadMask : false,
267     footerShow : true,
268     summaryFooterShow : false,
269     headerShow : true,
270     enableColumnResize: true,
271     disableAutoSize: false,
272   
273     rowSelection : false,
274     cellSelection : false,
275     layout : false,
276
277     minColumnWidth : 50,
278     
279     // Roo.Element - the tbody
280     bodyEl: false,  // <tbody> Roo.Element - thead element    
281     headEl: false,  // <thead> Roo.Element - thead element
282     resizeProxy : false, // proxy element for dragging?
283
284
285     
286     container: false, // used by gridpanel...
287     
288     lazyLoad : false,
289     
290     CSS : Roo.util.CSS,
291     
292     auto_hide_footer : false,
293     
294     view: false, // actually points to this..
295     
296     getAutoCreate : function()
297     {
298         var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
299         
300         cfg = {
301             tag: 'table',
302             cls : 'table', 
303             cn : []
304         };
305         // this get's auto added by panel.Grid
306         if (this.scrollBody) {
307             cfg.cls += ' table-body-fixed';
308         }    
309         if (this.striped) {
310             cfg.cls += ' table-striped';
311         }
312         
313         if (this.hover) {
314             cfg.cls += ' table-hover';
315         }
316         if (this.bordered) {
317             cfg.cls += ' table-bordered';
318         }
319         if (this.condensed) {
320             cfg.cls += ' table-condensed';
321         }
322         
323         if (this.responsive) {
324             cfg.cls += ' table-responsive';
325         }
326         
327         if (this.cls) {
328             cfg.cls+=  ' ' +this.cls;
329         }
330         
331         
332         
333         if (this.layout) {
334             cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
335         }
336         
337         if(this.store || this.cm){
338             if(this.headerShow){
339                 cfg.cn.push(this.renderHeader());
340             }
341             
342             cfg.cn.push(this.renderBody());
343             
344             if(this.footerShow){
345                 cfg.cn.push(this.renderFooter());
346             }
347
348             // where does this come from?
349             //cfg.cls+=  ' TableGrid';
350         }
351         
352         return { cn : [ cfg ] };
353     },
354     
355     initEvents : function()
356     {   
357         if(!this.store || !this.cm){
358             return;
359         }
360         if (this.selModel) {
361             this.selModel.initEvents();
362         }
363         
364         
365         //Roo.log('initEvents with ds!!!!');
366         
367         this.bodyEl = this.el.select('tbody', true).first();
368         this.headEl = this.el.select('thead', true).first();
369         this.mainFoot = this.el.select('tfoot', true).first();
370         
371         
372         
373         
374         Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
375             e.on('click', this.sort, this);
376         }, this);
377         
378         
379         // why is this done????? = it breaks dialogs??
380         //this.parent().el.setStyle('position', 'relative');
381         
382         
383         if (this.footer) {
384             this.footer.parentId = this.id;
385             this.footer.onRender(this.el.select('tfoot tr td').first(), null);
386             
387             if(this.lazyLoad){
388                 this.el.select('tfoot tr td').first().addClass('hide');
389             }
390         } 
391         
392         if(this.loadMask) {
393             this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
394         }
395         
396         this.store.on('load', this.onLoad, this);
397         this.store.on('beforeload', this.onBeforeLoad, this);
398         this.store.on('update', this.onUpdate, this);
399         this.store.on('add', this.onAdd, this);
400         this.store.on("clear", this.clear, this);
401         
402         this.el.on("contextmenu", this.onContextMenu, this);
403         
404         
405         this.cm.on("headerchange", this.onHeaderChange, this);
406         this.cm.on("hiddenchange", this.onHiddenChange, this, arguments);
407
408  //?? does bodyEl get replaced on render?
409         this.bodyEl.on("click", this.onClick, this);
410         this.bodyEl.on("dblclick", this.onDblClick, this);        
411         this.bodyEl.on('scroll', this.onBodyScroll, this);
412
413         // guessing mainbody will work - this relays usually caught by selmodel at present.
414         this.relayEvents(this.bodyEl, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
415   
416   
417         this.resizeProxy = Roo.get(document.body).createChild({ cls:"x-grid-resize-proxy", html: '&#160;' });
418         
419   
420         if(this.headEl && this.enableColumnResize !== false && Roo.grid.SplitDragZone){
421             new Roo.grid.SplitDragZone(this, this.headEl.dom, false); // not sure what 'lockedHd is for this implementation..)
422         }
423         
424         this.initCSS();
425     },
426     // Compatibility with grid - we implement all the view features at present.
427     getView : function()
428     {
429         return this;
430     },
431     
432     initCSS : function()
433     {
434         if(this.disableAutoSize) {
435             return;
436         }
437         
438         var cm = this.cm, styles = [];
439         this.CSS.removeStyleSheet(this.id + '-cssrules');
440         var headHeight = this.headEl ? this.headEl.dom.clientHeight : 0;
441         // we can honour xs/sm/md/xl  as widths...
442         // we first have to decide what widht we are currently at...
443         var sz = Roo.getGridSize();
444         
445         var total = 0;
446         var last = -1;
447         var cols = []; // visable cols.
448         var total_abs = 0;
449         for(var i = 0, len = cm.getColumnCount(); i < len; i++) {
450             var w = cm.getColumnWidth(i, false);
451             if(cm.isHidden(i)){
452                 cols.push( { rel : false, abs : 0 });
453                 continue;
454             }
455             if (w !== false) {
456                 cols.push( { rel : false, abs : w });
457                 total_abs += w;
458                 last = i; // not really..
459                 continue;
460             }
461             var w = cm.getColumnWidth(i, sz);
462             if (w > 0) {
463                 last = i
464             }
465             total += w;
466             cols.push( { rel : w, abs : false });
467         }
468         
469         var avail = this.bodyEl.dom.clientWidth - total_abs;
470         
471         var unitWidth = Math.floor(avail / total);
472         var rem = avail - (unitWidth * total);
473         
474         var hidden, width, pos = 0 , splithide , left;
475         for(var i = 0, len = cm.getColumnCount(); i < len; i++) {
476             
477             hidden = 'display:none;';
478             left = '';
479             width  = 'width:0px;';
480             splithide = '';
481             if(!cm.isHidden(i)){
482                 hidden = '';
483                 
484                 
485                 // we can honour xs/sm/md/xl ?
486                 var w = cols[i].rel == false ? cols[i].abs : (cols[i].rel * unitWidth);
487                 if (w===0) {
488                     hidden = 'display:none;';
489                 }
490                 // width should return a small number...
491                 if (i == last) {
492                     w+=rem; // add the remaining with..
493                 }
494                 pos += w;
495                 left = "left:" + (pos -4) + "px;";
496                 width = "width:" + w+ "px;";
497                 
498             }
499             if (this.responsive) {
500                 width = '';
501                 left = '';
502                 hidden = cm.isHidden(i) ? 'display:none;' : '';
503                 splithide = 'display: none;';
504             }
505             
506             styles.push( '#' , this.id , ' .x-col-' , i, " {", cm.config[i].css, width, hidden, "}\n" );
507             if (this.headEl) {
508                 if (i == last) {
509                     splithide = 'display:none;';
510                 }
511                 
512                 styles.push('#' , this.id , ' .x-hcol-' , i, " { ", width, hidden," }\n",
513                             '#' , this.id , ' .x-grid-split-' , i, " { ", left, splithide, 'height:', (headHeight - 4), "px;}\n",
514                             // this is the popover version..
515                             '.popover-inner #' , this.id , ' .x-grid-split-' , i, " { ", left, splithide, 'height:', 100, "%;}\n"
516                 );
517             }
518             
519         }
520         //Roo.log(styles.join(''));
521         this.CSS.createStyleSheet( styles.join(''), this.id + '-cssrules');
522         
523     },
524     
525     
526     
527     onContextMenu : function(e, t)
528     {
529         this.processEvent("contextmenu", e);
530     },
531     
532     processEvent : function(name, e)
533     {
534         if (name != 'touchstart' ) {
535             this.fireEvent(name, e);    
536         }
537         
538         var t = e.getTarget();
539         
540         var cell = Roo.get(t);
541         
542         if(!cell){
543             return;
544         }
545         
546         if(cell.findParent('tfoot', false, true)){
547             return;
548         }
549         
550         if(cell.findParent('thead', false, true)){
551             
552             if(e.getTarget().nodeName.toLowerCase() != 'th'){
553                 cell = Roo.get(t).findParent('th', false, true);
554                 if (!cell) {
555                     Roo.log("failed to find th in thead?");
556                     Roo.log(e.getTarget());
557                     return;
558                 }
559             }
560             
561             var cellIndex = cell.dom.cellIndex;
562             
563             var ename = name == 'touchstart' ? 'click' : name;
564             this.fireEvent("header" + ename, this, cellIndex, e);
565             
566             return;
567         }
568         
569         if(e.getTarget().nodeName.toLowerCase() != 'td'){
570             cell = Roo.get(t).findParent('td', false, true);
571             if (!cell) {
572                 Roo.log("failed to find th in tbody?");
573                 Roo.log(e.getTarget());
574                 return;
575             }
576         }
577         
578         var row = cell.findParent('tr', false, true);
579         var cellIndex = cell.dom.cellIndex;
580         var rowIndex = row.dom.rowIndex - 1;
581         
582         if(row !== false){
583             
584             this.fireEvent("row" + name, this, rowIndex, e);
585             
586             if(cell !== false){
587             
588                 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
589             }
590         }
591         
592     },
593     
594     onMouseover : function(e, el)
595     {
596         var cell = Roo.get(el);
597         
598         if(!cell){
599             return;
600         }
601         
602         if(e.getTarget().nodeName.toLowerCase() != 'td'){
603             cell = cell.findParent('td', false, true);
604         }
605         
606         var row = cell.findParent('tr', false, true);
607         var cellIndex = cell.dom.cellIndex;
608         var rowIndex = row.dom.rowIndex - 1; // start from 0
609         
610         this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
611         
612     },
613     
614     onMouseout : function(e, el)
615     {
616         var cell = Roo.get(el);
617         
618         if(!cell){
619             return;
620         }
621         
622         if(e.getTarget().nodeName.toLowerCase() != 'td'){
623             cell = cell.findParent('td', false, true);
624         }
625         
626         var row = cell.findParent('tr', false, true);
627         var cellIndex = cell.dom.cellIndex;
628         var rowIndex = row.dom.rowIndex - 1; // start from 0
629         
630         this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
631         
632     },
633     
634     onClick : function(e, el)
635     {
636         var cell = Roo.get(el);
637         
638         if(!cell || (!this.cellSelection && !this.rowSelection)){
639             return;
640         }
641         
642         if(e.getTarget().nodeName.toLowerCase() != 'td'){
643             cell = cell.findParent('td', false, true);
644         }
645         
646         if(!cell || typeof(cell) == 'undefined'){
647             return;
648         }
649         
650         var row = cell.findParent('tr', false, true);
651         
652         if(!row || typeof(row) == 'undefined'){
653             return;
654         }
655         
656         var cellIndex = cell.dom.cellIndex;
657         var rowIndex = this.getRowIndex(row);
658         
659         // why??? - should these not be based on SelectionModel?
660         //if(this.cellSelection){
661             this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
662         //}
663         
664         //if(this.rowSelection){
665             this.fireEvent('rowclick', this, row, rowIndex, e);
666         //}
667          
668     },
669         
670     onDblClick : function(e,el)
671     {
672         var cell = Roo.get(el);
673         
674         if(!cell || (!this.cellSelection && !this.rowSelection)){
675             return;
676         }
677         
678         if(e.getTarget().nodeName.toLowerCase() != 'td'){
679             cell = cell.findParent('td', false, true);
680         }
681         
682         if(!cell || typeof(cell) == 'undefined'){
683             return;
684         }
685         
686         var row = cell.findParent('tr', false, true);
687         
688         if(!row || typeof(row) == 'undefined'){
689             return;
690         }
691         
692         var cellIndex = cell.dom.cellIndex;
693         var rowIndex = this.getRowIndex(row);
694         
695         if(this.cellSelection){
696             this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
697         }
698         
699         if(this.rowSelection){
700             this.fireEvent('rowdblclick', this, row, rowIndex, e);
701         }
702     },
703     findRowIndex : function(el)
704     {
705         var cell = Roo.get(el);
706         if(!cell) {
707             return false;
708         }
709         var row = cell.findParent('tr', false, true);
710         
711         if(!row || typeof(row) == 'undefined'){
712             return false;
713         }
714         return this.getRowIndex(row);
715     },
716     sort : function(e,el)
717     {
718         var col = Roo.get(el);
719         
720         if(!col.hasClass('sortable')){
721             return;
722         }
723         
724         var sort = col.attr('sort');
725         var dir = 'ASC';
726         
727         if(col.select('i', true).first().hasClass('fa-arrow-up')){
728             dir = 'DESC';
729         }
730         
731         this.store.sortInfo = {field : sort, direction : dir};
732         
733         if (this.footer) {
734             Roo.log("calling footer first");
735             this.footer.onClick('first');
736         } else {
737         
738             this.store.load({ params : { start : 0 } });
739         }
740     },
741     
742     renderHeader : function()
743     {
744         var header = {
745             tag: 'thead',
746             cn : []
747         };
748         
749         var cm = this.cm;
750         this.totalWidth = 0;
751         
752         for(var i = 0, len = cm.getColumnCount(); i < len; i++){
753             
754             var config = cm.config[i];
755             
756             var c = {
757                 tag: 'th',
758                 cls : 'x-hcol-' + i,
759                 style : '',
760                 
761                 html: cm.getColumnHeader(i)
762             };
763             
764             var tooltip = cm.getColumnTooltip(i);
765             if (tooltip) {
766                 c.tooltip = tooltip;
767             }
768             
769             
770             var hh = '';
771             
772             if(typeof(config.sortable) != 'undefined' && config.sortable){
773                 c.cls += ' sortable';
774                 c.html = '<i class="fa"></i>' + c.html;
775             }
776             
777             // could use BS4 hidden-..-down 
778             
779             if(typeof(config.lgHeader) != 'undefined'){
780                 hh += '<span class="hidden-xs hidden-sm hidden-md ">' + config.lgHeader + '</span>';
781             }
782             
783             if(typeof(config.mdHeader) != 'undefined'){
784                 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
785             }
786             
787             if(typeof(config.smHeader) != 'undefined'){
788                 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
789             }
790             
791             if(typeof(config.xsHeader) != 'undefined'){
792                 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
793             }
794             
795             if(hh.length){
796                 c.html = hh;
797             }
798             
799             if(typeof(config.tooltip) != 'undefined'){
800                 c.tooltip = config.tooltip;
801             }
802             
803             if(typeof(config.colspan) != 'undefined'){
804                 c.colspan = config.colspan;
805             }
806             
807             // hidden is handled by CSS now
808             
809             if(typeof(config.dataIndex) != 'undefined'){
810                 c.sort = config.dataIndex;
811             }
812             
813            
814             
815             if(typeof(config.align) != 'undefined' && config.align.length){
816                 c.style += ' text-align:' + config.align + ';';
817             }
818             
819             /* width is done in CSS
820              *if(typeof(config.width) != 'undefined'){
821                 c.style += ' width:' + config.width + 'px;';
822                 this.totalWidth += config.width;
823             } else {
824                 this.totalWidth += 100; // assume minimum of 100 per column?
825             }
826             */
827             
828             if(typeof(config.cls) != 'undefined'){
829                 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
830             }
831             // this is the bit that doesnt reall work at all...
832             
833             if (this.responsive) {
834                  
835             
836                 ['xs','sm','md','lg'].map(function(size){
837                     
838                     if(typeof(config[size]) == 'undefined'){
839                         return;
840                     }
841                      
842                     if (!config[size]) { // 0 = hidden
843                         // BS 4 '0' is treated as hide that column and below.
844                         c.cls += ' hidden-' + size + ' hidden' + size + '-down';
845                         return;
846                     }
847                     
848                     c.cls += ' col-' + size + '-' + config[size] + (
849                         size == 'xs' ? (' col-' + config[size] ) : '' // bs4 col-{num} replaces col-xs
850                     );
851                     
852                     
853                 });
854             }
855             // at the end?
856             
857             c.html +=' <span class="x-grid-split x-grid-split-' + i + '"></span>';
858             
859             
860             
861             
862             header.cn.push(c)
863         }
864         
865         return header;
866     },
867     
868     renderBody : function()
869     {
870         var body = {
871             tag: 'tbody',
872             cn : [
873                 {
874                     tag: 'tr',
875                     cn : [
876                         {
877                             tag : 'td',
878                             colspan :  this.cm.getColumnCount()
879                         }
880                     ]
881                 }
882             ]
883         };
884         
885         return body;
886     },
887     
888     renderFooter : function()
889     {
890         var footer = {
891             tag: 'tfoot',
892             cn : [
893                 {
894                     tag: 'tr',
895                     cn : [
896                         {
897                             tag : 'td',
898                             colspan :  this.cm.getColumnCount()
899                         }
900                     ]
901                 }
902             ]
903         };
904         
905         return footer;
906     },
907
908     renderSummaryFooter : function()
909     {
910         var footer = {
911             tag: 'tfoot',
912             cn : []
913         };
914
915         var cm = this.cm;
916         
917         for(var i = 0, len = cm.getColumnCount(); i < len; i++){
918             
919             var config = cm.config[i];
920             
921             var c = {
922                 tag: 'td',
923                 cls : 'x-fcol-' + i,
924                 style : '',
925                 html: ''
926             };
927             
928             footer.cn.push(c)
929         }
930         
931         return footer;
932     },
933     
934     
935     
936     onLoad : function()
937     {
938 //        Roo.log('ds onload');
939         this.clear();
940         
941         var _this = this;
942         var cm = this.cm;
943         var ds = this.store;
944         
945         Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
946             e.select('i', true).removeClass(['fa-arrow-up', 'fa-arrow-down']);
947             if (_this.store.sortInfo) {
948                     
949                 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
950                     e.select('i', true).addClass(['fa-arrow-up']);
951                 }
952                 
953                 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
954                     e.select('i', true).addClass(['fa-arrow-down']);
955                 }
956             }
957         });
958         
959         var tbody =  this.bodyEl;
960               
961         if(ds.getCount() > 0){
962             ds.data.each(function(d,rowIndex){
963                 var row =  this.renderRow(cm, ds, rowIndex);
964                 
965                 tbody.createChild(row);
966                 
967                 var _this = this;
968                 
969                 if(row.cellObjects.length){
970                     Roo.each(row.cellObjects, function(r){
971                         _this.renderCellObject(r);
972                     })
973                 }
974                 
975             }, this);
976
977             if(!this.footerShow && this.summaryFooterShow) {
978                 var cellObjects = [];
979
980                 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
981             
982                     var config = cm.config[i];
983
984                     cellObjects.push({
985                         container : id,
986                         cfg : config.summaryFooter 
987                     })
988                     
989                     var c = {
990                         tag: 'td',
991                         cls : 'x-fcol-' + i,
992                         style : '',
993                         
994                         html: ''
995                     };
996                     
997                     footer.cn.push(c)
998                 }
999     
1000                 var id = Roo.id();
1001             }
1002         } else if (this.empty_results.length) {
1003             this.el.mask(this.empty_results, 'no-spinner');
1004         }
1005         
1006         var tfoot = this.el.select('tfoot', true).first();
1007         
1008         if(this.footerShow && this.auto_hide_footer && this.mainFoot){
1009             
1010             this.mainFoot.setVisibilityMode(Roo.Element.DISPLAY).hide();
1011             
1012             var total = this.ds.getTotalCount();
1013             
1014             if(this.footer.pageSize < total){
1015                 this.mainFoot.show();
1016             }
1017         }
1018         
1019         Roo.each(this.el.select('tbody td', true).elements, function(e){
1020             e.on('mouseover', _this.onMouseover, _this);
1021         });
1022         
1023         Roo.each(this.el.select('tbody td', true).elements, function(e){
1024             e.on('mouseout', _this.onMouseout, _this);
1025         });
1026         this.fireEvent('rowsrendered', this);
1027         
1028         this.autoSize();
1029         
1030         this.initCSS(); /// resize cols
1031
1032         
1033     },
1034     
1035     
1036     onUpdate : function(ds,record)
1037     {
1038         this.refreshRow(record);
1039         this.autoSize();
1040     },
1041     
1042     onRemove : function(ds, record, index, isUpdate){
1043         if(isUpdate !== true){
1044             this.fireEvent("beforerowremoved", this, index, record);
1045         }
1046         var bt = this.bodyEl.dom;
1047         
1048         var rows = this.el.select('tbody > tr', true).elements;
1049         
1050         if(typeof(rows[index]) != 'undefined'){
1051             bt.removeChild(rows[index].dom);
1052         }
1053         
1054 //        if(bt.rows[index]){
1055 //            bt.removeChild(bt.rows[index]);
1056 //        }
1057         
1058         if(isUpdate !== true){
1059             //this.stripeRows(index);
1060             //this.syncRowHeights(index, index);
1061             //this.layout();
1062             this.fireEvent("rowremoved", this, index, record);
1063         }
1064     },
1065     
1066     onAdd : function(ds, records, rowIndex)
1067     {
1068         //Roo.log('on Add called');
1069         // - note this does not handle multiple adding very well..
1070         var bt = this.bodyEl.dom;
1071         for (var i =0 ; i < records.length;i++) {
1072             //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
1073             //Roo.log(records[i]);
1074             //Roo.log(this.store.getAt(rowIndex+i));
1075             this.insertRow(this.store, rowIndex + i, false);
1076             return;
1077         }
1078         
1079     },
1080     
1081     
1082     refreshRow : function(record){
1083         var ds = this.store, index;
1084         if(typeof record == 'number'){
1085             index = record;
1086             record = ds.getAt(index);
1087         }else{
1088             index = ds.indexOf(record);
1089             if (index < 0) {
1090                 return; // should not happen - but seems to 
1091             }
1092         }
1093         this.insertRow(ds, index, true);
1094         this.autoSize();
1095         this.onRemove(ds, record, index+1, true);
1096         this.autoSize();
1097         //this.syncRowHeights(index, index);
1098         //this.layout();
1099         this.fireEvent("rowupdated", this, index, record);
1100     },
1101     // private - called by RowSelection
1102     onRowSelect : function(rowIndex){
1103         var row = this.getRowDom(rowIndex);
1104         row.addClass(['bg-info','info']);
1105     },
1106     // private - called by RowSelection
1107     onRowDeselect : function(rowIndex)
1108     {
1109         if (rowIndex < 0) {
1110             return;
1111         }
1112         var row = this.getRowDom(rowIndex);
1113         row.removeClass(['bg-info','info']);
1114     },
1115       /**
1116      * Focuses the specified row.
1117      * @param {Number} row The row index
1118      */
1119     focusRow : function(row)
1120     {
1121         //Roo.log('GridView.focusRow');
1122         var x = this.bodyEl.dom.scrollLeft;
1123         this.focusCell(row, 0, false);
1124         this.bodyEl.dom.scrollLeft = x;
1125
1126     },
1127      /**
1128      * Focuses the specified cell.
1129      * @param {Number} row The row index
1130      * @param {Number} col The column index
1131      * @param {Boolean} hscroll false to disable horizontal scrolling
1132      */
1133     focusCell : function(row, col, hscroll)
1134     {
1135         //Roo.log('GridView.focusCell');
1136         var el = this.ensureVisible(row, col, hscroll);
1137         // not sure what focusEL achives = it's a <a> pos relative 
1138         //this.focusEl.alignTo(el, "tl-tl");
1139         //if(Roo.isGecko){
1140         //    this.focusEl.focus();
1141         //}else{
1142         //    this.focusEl.focus.defer(1, this.focusEl);
1143         //}
1144     },
1145     
1146      /**
1147      * Scrolls the specified cell into view
1148      * @param {Number} row The row index
1149      * @param {Number} col The column index
1150      * @param {Boolean} hscroll false to disable horizontal scrolling
1151      */
1152     ensureVisible : function(row, col, hscroll)
1153     {
1154         //Roo.log('GridView.ensureVisible,' + row + ',' + col);
1155         //return null; //disable for testing.
1156         if(typeof row != "number"){
1157             row = row.rowIndex;
1158         }
1159         if(row < 0 && row >= this.ds.getCount()){
1160             return  null;
1161         }
1162         col = (col !== undefined ? col : 0);
1163         var cm = this.cm;
1164         while(cm.isHidden(col)){
1165             col++;
1166         }
1167
1168         var el = this.getCellDom(row, col);
1169         if(!el){
1170             return null;
1171         }
1172         var c = this.bodyEl.dom;
1173
1174         var ctop = parseInt(el.offsetTop, 10);
1175         var cleft = parseInt(el.offsetLeft, 10);
1176         var cbot = ctop + el.offsetHeight;
1177         var cright = cleft + el.offsetWidth;
1178
1179         //var ch = c.clientHeight - this.mainHd.dom.offsetHeight;
1180         var ch = 0; //?? header is not withing the area?
1181         var stop = parseInt(c.scrollTop, 10);
1182         var sleft = parseInt(c.scrollLeft, 10);
1183         var sbot = stop + ch;
1184         var sright = sleft + c.clientWidth;
1185         /*
1186         Roo.log('GridView.ensureVisible:' +
1187                 ' ctop:' + ctop +
1188                 ' c.clientHeight:' + c.clientHeight +
1189                 ' this.mainHd.dom.offsetHeight:' + this.mainHd.dom.offsetHeight +
1190                 ' stop:' + stop +
1191                 ' cbot:' + cbot +
1192                 ' sbot:' + sbot +
1193                 ' ch:' + ch  
1194                 );
1195         */
1196         if(ctop < stop){
1197             c.scrollTop = ctop;
1198             //Roo.log("set scrolltop to ctop DISABLE?");
1199         }else if(cbot > sbot){
1200             //Roo.log("set scrolltop to cbot-ch");
1201             c.scrollTop = cbot-ch;
1202         }
1203
1204         if(hscroll !== false){
1205             if(cleft < sleft){
1206                 c.scrollLeft = cleft;
1207             }else if(cright > sright){
1208                 c.scrollLeft = cright-c.clientWidth;
1209             }
1210         }
1211
1212         return el;
1213     },
1214     
1215     
1216     insertRow : function(dm, rowIndex, isUpdate){
1217         
1218         if(!isUpdate){
1219             this.fireEvent("beforerowsinserted", this, rowIndex);
1220         }
1221             //var s = this.getScrollState();
1222         var row = this.renderRow(this.cm, this.store, rowIndex);
1223         // insert before rowIndex..
1224         var e = this.bodyEl.createChild(row,this.getRowDom(rowIndex));
1225         
1226         var _this = this;
1227                 
1228         if(row.cellObjects.length){
1229             Roo.each(row.cellObjects, function(r){
1230                 _this.renderCellObject(r);
1231             })
1232         }
1233             
1234         if(!isUpdate){
1235             this.fireEvent("rowsinserted", this, rowIndex);
1236             //this.syncRowHeights(firstRow, lastRow);
1237             //this.stripeRows(firstRow);
1238             //this.layout();
1239         }
1240         
1241     },
1242     
1243     
1244     getRowDom : function(rowIndex)
1245     {
1246         var rows = this.el.select('tbody > tr', true).elements;
1247         
1248         return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
1249         
1250     },
1251     getCellDom : function(rowIndex, colIndex)
1252     {
1253         var row = this.getRowDom(rowIndex);
1254         if (row === false) {
1255             return false;
1256         }
1257         var cols = row.select('td', true).elements;
1258         return (typeof(cols[colIndex]) == 'undefined') ? false : cols[colIndex];
1259         
1260     },
1261     
1262     // returns the object tree for a tr..
1263   
1264     
1265     renderRow : function(cm, ds, rowIndex) 
1266     {
1267         var d = ds.getAt(rowIndex);
1268         
1269         var row = {
1270             tag : 'tr',
1271             cls : 'x-row-' + rowIndex,
1272             cn : []
1273         };
1274             
1275         var cellObjects = [];
1276         
1277         for(var i = 0, len = cm.getColumnCount(); i < len; i++){
1278             var config = cm.config[i];
1279             
1280             var renderer = cm.getRenderer(i);
1281             var value = '';
1282             var id = false;
1283             
1284             if(typeof(renderer) !== 'undefined'){
1285                 value = renderer(d.data[cm.getDataIndex(i)], false, d);
1286             }
1287             // if object are returned, then they are expected to be Roo.bootstrap.Component instances
1288             // and are rendered into the cells after the row is rendered - using the id for the element.
1289             
1290             if(typeof(value) === 'object'){
1291                 id = Roo.id();
1292                 cellObjects.push({
1293                     container : id,
1294                     cfg : value 
1295                 })
1296             }
1297             
1298             var rowcfg = {
1299                 record: d,
1300                 rowIndex : rowIndex,
1301                 colIndex : i,
1302                 rowClass : ''
1303             };
1304
1305             this.fireEvent('rowclass', this, rowcfg);
1306             
1307             var td = {
1308                 tag: 'td',
1309                 // this might end up displaying HTML?
1310                 // this is too messy... - better to only do it on columsn you know are going to be too long
1311                 //tooltip : (typeof(value) === 'object') ? '' : value,
1312                 cls : rowcfg.rowClass + ' x-col-' + i,
1313                 style: '',
1314                 html: (typeof(value) === 'object') ? '' : value
1315             };
1316             
1317             if (id) {
1318                 td.id = id;
1319             }
1320             
1321             if(typeof(config.colspan) != 'undefined'){
1322                 td.colspan = config.colspan;
1323             }
1324             
1325             
1326             
1327             if(typeof(config.align) != 'undefined' && config.align.length){
1328                 td.style += ' text-align:' + config.align + ';';
1329             }
1330             if(typeof(config.valign) != 'undefined' && config.valign.length){
1331                 td.style += ' vertical-align:' + config.valign + ';';
1332             }
1333             /*
1334             if(typeof(config.width) != 'undefined'){
1335                 td.style += ' width:' +  config.width + 'px;';
1336             }
1337             */
1338             
1339             if(typeof(config.cursor) != 'undefined'){
1340                 td.style += ' cursor:' +  config.cursor + ';';
1341             }
1342             
1343             if(typeof(config.cls) != 'undefined'){
1344                 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
1345             }
1346             if (this.responsive) {
1347                 ['xs','sm','md','lg'].map(function(size){
1348                     
1349                     if(typeof(config[size]) == 'undefined'){
1350                         return;
1351                     }
1352                     
1353                     
1354                       
1355                     if (!config[size]) { // 0 = hidden
1356                         // BS 4 '0' is treated as hide that column and below.
1357                         td.cls += ' hidden-' + size + ' hidden' + size + '-down';
1358                         return;
1359                     }
1360                     
1361                     td.cls += ' col-' + size + '-' + config[size] + (
1362                         size == 'xs' ? (' col-' +   config[size] ) : '' // bs4 col-{num} replaces col-xs
1363                     );
1364                      
1365     
1366                 });
1367             }
1368             row.cn.push(td);
1369            
1370         }
1371         
1372         row.cellObjects = cellObjects;
1373         
1374         return row;
1375           
1376     },
1377     
1378     
1379     
1380     onBeforeLoad : function()
1381     {
1382         this.el.unmask(); // if needed.
1383     },
1384      /**
1385      * Remove all rows
1386      */
1387     clear : function()
1388     {
1389         this.el.select('tbody', true).first().dom.innerHTML = '';
1390     },
1391     /**
1392      * Show or hide a row.
1393      * @param {Number} rowIndex to show or hide
1394      * @param {Boolean} state hide
1395      */
1396     setRowVisibility : function(rowIndex, state)
1397     {
1398         var bt = this.bodyEl.dom;
1399         
1400         var rows = this.el.select('tbody > tr', true).elements;
1401         
1402         if(typeof(rows[rowIndex]) == 'undefined'){
1403             return;
1404         }
1405         rows[rowIndex][ state ? 'removeClass' : 'addClass']('d-none');
1406         
1407     },
1408     
1409     
1410     getSelectionModel : function(){
1411         if(!this.selModel){
1412             this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
1413         }
1414         return this.selModel;
1415     },
1416     /*
1417      * Render the Roo.bootstrap object from renderder
1418      */
1419     renderCellObject : function(r)
1420     {
1421         var _this = this;
1422         
1423         r.cfg.parentId = (typeof(r.container) == 'string') ? r.container : r.container.id;
1424         
1425         var t = r.cfg.render(r.container);
1426         
1427         if(r.cfg.cn){
1428             Roo.each(r.cfg.cn, function(c){
1429                 var child = {
1430                     container: t.getChildContainer(),
1431                     cfg: c
1432                 };
1433                 _this.renderCellObject(child);
1434             })
1435         }
1436     },
1437     /**
1438      * get the Row Index from a dom element.
1439      * @param {Roo.Element} row The row to look for
1440      * @returns {Number} the row
1441      */
1442     getRowIndex : function(row)
1443     {
1444         var rowIndex = -1;
1445         
1446         Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
1447             if(el != row){
1448                 return;
1449             }
1450             
1451             rowIndex = index;
1452         });
1453         
1454         return rowIndex;
1455     },
1456     /**
1457      * get the header TH element for columnIndex
1458      * @param {Number} columnIndex
1459      * @returns {Roo.Element}
1460      */
1461     getHeaderIndex: function(colIndex)
1462     {
1463         var cols = this.headEl.select('th', true).elements;
1464         return cols[colIndex]; 
1465     },
1466     /**
1467      * get the Column Index from a dom element. (using regex on x-hcol-{colid})
1468      * @param {domElement} cell to look for
1469      * @returns {Number} the column
1470      */
1471     getCellIndex : function(cell)
1472     {
1473         var id = String(cell.className).match(Roo.bootstrap.Table.cellRE);
1474         if(id){
1475             return parseInt(id[1], 10);
1476         }
1477         return 0;
1478     },
1479      /**
1480      * Returns the grid's underlying element = used by panel.Grid
1481      * @return {Element} The element
1482      */
1483     getGridEl : function(){
1484         return this.el;
1485     },
1486      /**
1487      * Forces a resize - used by panel.Grid
1488      * @return {Element} The element
1489      */
1490     autoSize : function()
1491     {
1492         if(this.disableAutoSize) {
1493             return;
1494         }
1495         //var ctr = Roo.get(this.container.dom.parentElement);
1496         var ctr = Roo.get(this.el.dom);
1497         
1498         var thd = this.getGridEl().select('thead',true).first();
1499         var tbd = this.getGridEl().select('tbody', true).first();
1500         var tfd = this.getGridEl().select('tfoot', true).first();
1501         
1502         var cw = ctr.getWidth();
1503         this.getGridEl().select('tfoot tr, tfoot  td',true).setWidth(cw);
1504         
1505         if (tbd) {
1506             
1507             tbd.setWidth(ctr.getWidth());
1508             // if the body has a max height - and then scrolls - we should perhaps set up the height here
1509             // this needs fixing for various usage - currently only hydra job advers I think..
1510             //tdb.setHeight(
1511             //        ctr.getHeight() - ((thd ? thd.getHeight() : 0) + (tfd ? tfd.getHeight() : 0))
1512             //); 
1513             var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
1514             cw -= barsize;
1515         }
1516         cw = Math.max(cw, this.totalWidth);
1517         this.getGridEl().select('tbody tr',true).setWidth(cw);
1518         this.initCSS();
1519         
1520         // resize 'expandable coloumn?
1521         
1522         return; // we doe not have a view in this design..
1523         
1524     },
1525     onBodyScroll: function()
1526     {
1527         //Roo.log("body scrolled');" + this.bodyEl.dom.scrollLeft);
1528         if(this.headEl){
1529             this.headEl.setStyle({
1530                 'position' : 'relative',
1531                 'left': (-1* this.bodyEl.dom.scrollLeft) + 'px'
1532             });
1533         }
1534         
1535         if(this.lazyLoad){
1536             
1537             var scrollHeight = this.bodyEl.dom.scrollHeight;
1538             
1539             var scrollTop = Math.ceil(this.bodyEl.getScroll().top);
1540             
1541             var height = this.bodyEl.getHeight();
1542             
1543             if(scrollHeight - height == scrollTop) {
1544                 
1545                 var total = this.ds.getTotalCount();
1546                 
1547                 if(this.footer.cursor + this.footer.pageSize < total){
1548                     
1549                     this.footer.ds.load({
1550                         params : {
1551                             start : this.footer.cursor + this.footer.pageSize,
1552                             limit : this.footer.pageSize
1553                         },
1554                         add : true
1555                     });
1556                 }
1557             }
1558             
1559         }
1560     },
1561     onColumnSplitterMoved : function(i, diff)
1562     {
1563         this.userResized = true;
1564         
1565         var cm = this.colModel;
1566         
1567         var w = this.getHeaderIndex(i).getWidth() + diff;
1568         
1569         
1570         cm.setColumnWidth(i, w, true);
1571         this.initCSS();
1572         //var cid = cm.getColumnId(i); << not used in this version?
1573        /* Roo.log(['#' + this.id + ' .x-col-' + i, "width", w + "px"]);
1574         
1575         this.CSS.updateRule( '#' + this.id + ' .x-col-' + i, "width", w + "px");
1576         this.CSS.updateRule('#' + this.id + ' .x-hcol-' + i, "width", w + "px");
1577         this.CSS.updateRule('#' + this.id + ' .x-grid-split-' + i, "left", w + "px");
1578 */
1579         //this.updateSplitters();
1580         //this.layout(); << ??
1581         this.fireEvent("columnresize", i, w);
1582     },
1583     onHeaderChange : function()
1584     {
1585         var header = this.renderHeader();
1586         var table = this.el.select('table', true).first();
1587         
1588         this.headEl.remove();
1589         this.headEl = table.createChild(header, this.bodyEl, false);
1590         
1591         Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
1592             e.on('click', this.sort, this);
1593         }, this);
1594         
1595         if(this.enableColumnResize !== false && Roo.grid.SplitDragZone){
1596             new Roo.grid.SplitDragZone(this, this.headEl.dom, false); // not sure what 'lockedHd is for this implementation..)
1597         }
1598         
1599     },
1600     
1601     onHiddenChange : function(colModel, colIndex, hidden)
1602     {
1603         /*
1604         this.cm.setHidden()
1605         var thSelector = '#' + this.id + ' .x-hcol-' + colIndex;
1606         var tdSelector = '#' + this.id + ' .x-col-' + colIndex;
1607         
1608         this.CSS.updateRule(thSelector, "display", "");
1609         this.CSS.updateRule(tdSelector, "display", "");
1610         
1611         if(hidden){
1612             this.CSS.updateRule(thSelector, "display", "none");
1613             this.CSS.updateRule(tdSelector, "display", "none");
1614         }
1615         */
1616         // onload calls initCSS()
1617         this.onHeaderChange();
1618         this.onLoad();
1619     },
1620     
1621     setColumnWidth: function(col_index, width)
1622     {
1623         // width = "md-2 xs-2..."
1624         if(!this.colModel.config[col_index]) {
1625             return;
1626         }
1627         
1628         var w = width.split(" ");
1629         
1630         var rows = this.el.dom.getElementsByClassName("x-col-"+col_index);
1631         
1632         var h_row = this.el.dom.getElementsByClassName("x-hcol-"+col_index);
1633         
1634         
1635         for(var j = 0; j < w.length; j++) {
1636             
1637             if(!w[j]) {
1638                 continue;
1639             }
1640             
1641             var size_cls = w[j].split("-");
1642             
1643             if(!Number.isInteger(size_cls[1] * 1)) {
1644                 continue;
1645             }
1646             
1647             if(!this.colModel.config[col_index][size_cls[0]]) {
1648                 continue;
1649             }
1650             
1651             if(!h_row[0].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
1652                 continue;
1653             }
1654             
1655             h_row[0].classList.replace(
1656                 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
1657                 "col-"+size_cls[0]+"-"+size_cls[1]
1658             );
1659             
1660             for(var i = 0; i < rows.length; i++) {
1661                 
1662                 var size_cls = w[j].split("-");
1663                 
1664                 if(!Number.isInteger(size_cls[1] * 1)) {
1665                     continue;
1666                 }
1667                 
1668                 if(!this.colModel.config[col_index][size_cls[0]]) {
1669                     continue;
1670                 }
1671                 
1672                 if(!rows[i].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
1673                     continue;
1674                 }
1675                 
1676                 rows[i].classList.replace(
1677                     "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
1678                     "col-"+size_cls[0]+"-"+size_cls[1]
1679                 );
1680             }
1681             
1682             this.colModel.config[col_index][size_cls[0]] = size_cls[1];
1683         }
1684     }
1685 });
1686
1687 // currently only used to find the split on drag.. 
1688 Roo.bootstrap.Table.cellRE = /(?:.*?)x-grid-(?:hd|cell|split)-([\d]+)(?:.*?)/;
1689
1690 /**
1691  * @depricated
1692 */
1693 Roo.bootstrap.Table.AbstractSelectionModel = Roo.grid.AbstractSelectionModel;
1694 Roo.bootstrap.Table.RowSelectionModel = Roo.grid.RowSelectionModel;