Roo/bootstrap/Table.js
[roojs1] / Roo / bootstrap / Table.js
1 /*
2  * - LGPL
3  *
4  * table
5  * 
6  */
7
8 /**
9  * @class Roo.bootstrap.Table
10  * @extends Roo.bootstrap.Component
11  * Bootstrap Table class
12  * @cfg {String} cls table class
13  * @cfg {String} align (left|center|right) Specifies the alignment of a table according to surrounding text
14  * @cfg {String} bgcolor Specifies the background color for a table
15  * @cfg {Number} border Specifies whether the table cells should have borders or not
16  * @cfg {Number} cellpadding Specifies the space between the cell wall and the cell content
17  * @cfg {Number} cellspacing Specifies the space between cells
18  * @cfg {String} frame Specifies which parts of the outside borders that should be visible
19  * @cfg {String} rules Specifies which parts of the inside borders that should be visible
20  * @cfg {String} sortable Specifies that the table should be sortable
21  * @cfg {String} summary Specifies a summary of the content of a table
22  * @cfg {Number} width Specifies the width of a table
23  * @cfg {String} layout table layout (auto | fixed | initial | inherit)
24  * 
25  * @cfg {boolean} striped Should the rows be alternative striped
26  * @cfg {boolean} bordered Add borders to the table
27  * @cfg {boolean} hover Add hover highlighting
28  * @cfg {boolean} condensed Format condensed
29  * @cfg {boolean} responsive Format condensed
30  * @cfg {Boolean} loadMask (true|false) default false
31  * @cfg {Boolean} footerShow (true|false) generate tfoot, default true
32  * @cfg {Boolean} headerShow (true|false) generate thead, default true
33  * @cfg {Boolean} rowSelection (true|false) default false
34  * @cfg {Boolean} cellSelection (true|false) default false
35  * @cfg {Roo.bootstrap.PagingToolbar} footer  a paging toolbar
36  
37  * 
38  * @constructor
39  * Create a new Table
40  * @param {Object} config The config object
41  */
42
43 Roo.bootstrap.Table = function(config){
44     Roo.bootstrap.Table.superclass.constructor.call(this, config);
45     
46     // BC...
47     this.rowSelection = (typeof(config.RowSelection) != 'undefined') ? config.RowSelection : this.rowSelection;
48     this.cellSelection = (typeof(config.CellSelection) != 'undefined') ? config.CellSelection : this.cellSelection;
49     this.headerShow = (typeof(config.thead) != 'undefined') ? config.thead : this.headerShow;
50     this.footerShow = (typeof(config.tfoot) != 'undefined') ? config.tfoot : this.footerShow;
51     
52     
53     if (this.sm) {
54         this.selModel = Roo.factory(this.sm, Roo.bootstrap.Table);
55         this.sm = this.selModel;
56         this.sm.xmodule = this.xmodule || false;
57     }
58     if (this.cm && typeof(this.cm.config) == 'undefined') {
59         this.colModel = new Roo.grid.ColumnModel(this.cm);
60         this.cm = this.colModel;
61         this.cm.xmodule = this.xmodule || false;
62     }
63     if (this.store) {
64         this.store= Roo.factory(this.store, Roo.data);
65         this.ds = this.store;
66         this.ds.xmodule = this.xmodule || false;
67          
68     }
69     if (this.footer && this.store) {
70         this.footer.dataSource = this.ds;
71         this.footer = Roo.factory(this.footer);
72     }
73     
74     /** @private */
75     this.addEvents({
76         /**
77          * @event cellclick
78          * Fires when a cell is clicked
79          * @param {Roo.bootstrap.Table} this
80          * @param {Roo.Element} el
81          * @param {Number} rowIndex
82          * @param {Number} columnIndex
83          * @param {Roo.EventObject} e
84          */
85         "cellclick" : true,
86         /**
87          * @event celldblclick
88          * Fires when a cell is double clicked
89          * @param {Roo.bootstrap.Table} this
90          * @param {Roo.Element} el
91          * @param {Number} rowIndex
92          * @param {Number} columnIndex
93          * @param {Roo.EventObject} e
94          */
95         "celldblclick" : true,
96         /**
97          * @event rowclick
98          * Fires when a row is clicked
99          * @param {Roo.bootstrap.Table} this
100          * @param {Roo.Element} el
101          * @param {Number} rowIndex
102          * @param {Roo.EventObject} e
103          */
104         "rowclick" : true,
105         /**
106          * @event rowdblclick
107          * Fires when a row is double clicked
108          * @param {Roo.bootstrap.Table} this
109          * @param {Roo.Element} el
110          * @param {Number} rowIndex
111          * @param {Roo.EventObject} e
112          */
113         "rowdblclick" : true,
114         /**
115          * @event mouseover
116          * Fires when a mouseover occur
117          * @param {Roo.bootstrap.Table} this
118          * @param {Roo.Element} el
119          * @param {Number} rowIndex
120          * @param {Number} columnIndex
121          * @param {Roo.EventObject} e
122          */
123         "mouseover" : true,
124         /**
125          * @event mouseout
126          * Fires when a mouseout occur
127          * @param {Roo.bootstrap.Table} this
128          * @param {Roo.Element} el
129          * @param {Number} rowIndex
130          * @param {Number} columnIndex
131          * @param {Roo.EventObject} e
132          */
133         "mouseout" : true,
134         /**
135          * @event rowclass
136          * Fires when a row is rendered, so you can change add a style to it.
137          * @param {Roo.bootstrap.Table} this
138          * @param {Object} rowcfg   contains record  rowIndex colIndex and rowClass - set rowClass to add a style.
139          */
140         'rowclass' : true,
141           /**
142          * @event rowsrendered
143          * Fires when all the  rows have been rendered
144          * @param {Roo.bootstrap.Table} this
145          */
146         'rowsrendered' : true,
147         /**
148          * @event contextmenu
149          * The raw contextmenu event for the entire grid.
150          * @param {Roo.EventObject} e
151          */
152         "contextmenu" : true,
153         /**
154          * @event rowcontextmenu
155          * Fires when a row is right clicked
156          * @param {Roo.bootstrap.Table} this
157          * @param {Number} rowIndex
158          * @param {Roo.EventObject} e
159          */
160         "rowcontextmenu" : true,
161         /**
162          * @event cellcontextmenu
163          * Fires when a cell is right clicked
164          * @param {Roo.bootstrap.Table} this
165          * @param {Number} rowIndex
166          * @param {Number} cellIndex
167          * @param {Roo.EventObject} e
168          */
169          "cellcontextmenu" : true,
170          /**
171          * @event headercontextmenu
172          * Fires when a header is right clicked
173          * @param {Roo.bootstrap.Table} this
174          * @param {Number} columnIndex
175          * @param {Roo.EventObject} e
176          */
177         "headercontextmenu" : true
178     });
179 };
180
181 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
182     
183     cls: false,
184     align: false,
185     bgcolor: false,
186     border: false,
187     cellpadding: false,
188     cellspacing: false,
189     frame: false,
190     rules: false,
191     sortable: false,
192     summary: false,
193     width: false,
194     striped : false,
195     bordered: false,
196     hover:  false,
197     condensed : false,
198     responsive : false,
199     sm : false,
200     cm : false,
201     store : false,
202     loadMask : false,
203     footerShow : true,
204     headerShow : true,
205   
206     rowSelection : false,
207     cellSelection : false,
208     layout : false,
209     
210     // Roo.Element - the tbody
211     mainBody: false, 
212     
213     getAutoCreate : function(){
214         var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
215         
216         cfg = {
217             tag: 'table',
218             cls : 'table',
219             cn : []
220         };
221             
222         if (this.striped) {
223             cfg.cls += ' table-striped';
224         }
225         
226         if (this.hover) {
227             cfg.cls += ' table-hover';
228         }
229         if (this.bordered) {
230             cfg.cls += ' table-bordered';
231         }
232         if (this.condensed) {
233             cfg.cls += ' table-condensed';
234         }
235         if (this.responsive) {
236             cfg.cls += ' table-responsive';
237         }
238         
239         if (this.cls) {
240             cfg.cls+=  ' ' +this.cls;
241         }
242         
243         // this lot should be simplifed...
244         
245         if (this.align) {
246             cfg.align=this.align;
247         }
248         if (this.bgcolor) {
249             cfg.bgcolor=this.bgcolor;
250         }
251         if (this.border) {
252             cfg.border=this.border;
253         }
254         if (this.cellpadding) {
255             cfg.cellpadding=this.cellpadding;
256         }
257         if (this.cellspacing) {
258             cfg.cellspacing=this.cellspacing;
259         }
260         if (this.frame) {
261             cfg.frame=this.frame;
262         }
263         if (this.rules) {
264             cfg.rules=this.rules;
265         }
266         if (this.sortable) {
267             cfg.sortable=this.sortable;
268         }
269         if (this.summary) {
270             cfg.summary=this.summary;
271         }
272         if (this.width) {
273             cfg.width=this.width;
274         }
275         if (this.layout) {
276             cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
277         }
278         
279         if(this.store || this.cm){
280             if(this.headerShow){
281                 cfg.cn.push(this.renderHeader());
282             }
283             
284             cfg.cn.push(this.renderBody());
285             
286             if(this.footerShow){
287                 cfg.cn.push(this.renderFooter());
288             }
289             
290             cfg.cls+=  ' TableGrid';
291         }
292         
293         return { cn : [ cfg ] };
294     },
295     
296     initEvents : function()
297     {   
298         if(!this.store || !this.cm){
299             return;
300         }
301         
302         //Roo.log('initEvents with ds!!!!');
303         
304         this.mainBody = this.el.select('tbody', true).first();
305         
306         
307         var _this = this;
308         
309         Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
310             e.on('click', _this.sort, _this);
311         });
312         
313         this.el.on("click", this.onClick, this);
314         this.el.on("dblclick", this.onDblClick, this);
315         
316         // why is this done????? = it breaks dialogs??
317         //this.parent().el.setStyle('position', 'relative');
318         
319         
320         if (this.footer) {
321             this.footer.parentId = this.id;
322             this.footer.onRender(this.el.select('tfoot tr td').first(), null);        
323         }
324         
325         this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
326         
327         this.store.on('load', this.onLoad, this);
328         this.store.on('beforeload', this.onBeforeLoad, this);
329         this.store.on('update', this.onUpdate, this);
330         this.store.on('add', this.onAdd, this);
331         
332         this.el.on("contextmenu", this.onContextMenu, this);
333         
334     },
335     
336     onContextMenu : function(e, t)
337     {
338         this.processEvent("contextmenu", e);
339     },
340     
341     processEvent : function(name, e)
342     {
343         if (name != 'touchstart' ) {
344             this.fireEvent(name, e);    
345         }
346         
347         var t = e.getTarget();
348         
349         var cell = Roo.get(t);
350         
351         if(!cell){
352             return;
353         }
354         
355         if(cell.findParent('tfoot', false, true)){
356             return;
357         }
358         
359         if(cell.findParent('thead', false, true)){
360             
361             if(e.getTarget().nodeName.toLowerCase() != 'th'){
362                 cell = Roo.get(t).findParent('th', false, true);
363             }
364             
365             var cellIndex = cell.dom.cellIndex;
366             
367             var ename = name == 'touchstart' ? 'click' : name;
368             this.fireEvent("header" + ename, this, cellIndex, e);
369             
370             return;
371         }
372         
373         if(e.getTarget().nodeName.toLowerCase() != 'td'){
374             cell = Roo.get(t).findParent('td', false, true);
375         }
376         
377         var row = cell.findParent('tr', false, true);
378         var cellIndex = cell.dom.cellIndex;
379         var rowIndex = row.dom.rowIndex - 1;
380         
381         if(row !== false){
382             
383             this.fireEvent("row" + name, this, rowIndex, e);
384             
385             if(cell !== false){
386             
387                 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
388             }
389         }
390         
391     },
392     
393     onMouseover : function(e, el)
394     {
395         var cell = Roo.get(el);
396         
397         if(!cell){
398             return;
399         }
400         
401         if(e.getTarget().nodeName.toLowerCase() != 'td'){
402             cell = cell.findParent('td', false, true);
403         }
404         
405         var row = cell.findParent('tr', false, true);
406         var cellIndex = cell.dom.cellIndex;
407         var rowIndex = row.dom.rowIndex - 1; // start from 0
408         
409         this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
410         
411     },
412     
413     onMouseout : function(e, el)
414     {
415         var cell = Roo.get(el);
416         
417         if(!cell){
418             return;
419         }
420         
421         if(e.getTarget().nodeName.toLowerCase() != 'td'){
422             cell = cell.findParent('td', false, true);
423         }
424         
425         var row = cell.findParent('tr', false, true);
426         var cellIndex = cell.dom.cellIndex;
427         var rowIndex = row.dom.rowIndex - 1; // start from 0
428         
429         this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
430         
431     },
432     
433     onClick : function(e, el)
434     {
435         var cell = Roo.get(el);
436         
437         if(!cell || (!this.cellSelection && !this.rowSelection)){
438             return;
439         }
440         
441         if(e.getTarget().nodeName.toLowerCase() != 'td'){
442             cell = cell.findParent('td', false, true);
443         }
444         
445         if(!cell || typeof(cell) == 'undefined'){
446             return;
447         }
448         
449         var row = cell.findParent('tr', false, true);
450         
451         if(!row || typeof(row) == 'undefined'){
452             return;
453         }
454         
455         var cellIndex = cell.dom.cellIndex;
456         var rowIndex = this.getRowIndex(row);
457         
458         // why??? - should these not be based on SelectionModel?
459         if(this.cellSelection){
460             this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
461         }
462         
463         if(this.rowSelection){
464             this.fireEvent('rowclick', this, row, rowIndex, e);
465         }
466         
467         
468     },
469     
470     onDblClick : function(e,el)
471     {
472         var cell = Roo.get(el);
473         
474         if(!cell || (!this.CellSelection && !this.RowSelection)){
475             return;
476         }
477         
478         if(e.getTarget().nodeName.toLowerCase() != 'td'){
479             cell = cell.findParent('td', false, true);
480         }
481         
482         if(!cell || typeof(cell) == 'undefined'){
483             return;
484         }
485         
486         var row = cell.findParent('tr', false, true);
487         
488         if(!row || typeof(row) == 'undefined'){
489             return;
490         }
491         
492         var cellIndex = cell.dom.cellIndex;
493         var rowIndex = this.getRowIndex(row);
494         
495         if(this.CellSelection){
496             this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
497         }
498         
499         if(this.RowSelection){
500             this.fireEvent('rowdblclick', this, row, rowIndex, e);
501         }
502     },
503     
504     sort : function(e,el)
505     {
506         var col = Roo.get(el);
507         
508         if(!col.hasClass('sortable')){
509             return;
510         }
511         
512         var sort = col.attr('sort');
513         var dir = 'ASC';
514         
515         if(col.hasClass('glyphicon-arrow-up')){
516             dir = 'DESC';
517         }
518         
519         this.store.sortInfo = {field : sort, direction : dir};
520         
521         if (this.footer) {
522             Roo.log("calling footer first");
523             this.footer.onClick('first');
524         } else {
525         
526             this.store.load({ params : { start : 0 } });
527         }
528     },
529     
530     renderHeader : function()
531     {
532         var header = {
533             tag: 'thead',
534             cn : []
535         };
536         
537         var cm = this.cm;
538         
539         for(var i = 0, len = cm.getColumnCount(); i < len; i++){
540             
541             var config = cm.config[i];
542             
543             var c = {
544                 tag: 'th',
545                 style : '',
546                 html: cm.getColumnHeader(i)
547             };
548             
549             var hh = '';
550             
551             if(typeof(config.lgHeader) != 'undefined'){
552                 hh += '<span class="hidden-xs hidden-sm hidden-md">' + config.lgHeader + '</span>';
553             }
554             
555             if(typeof(config.mdHeader) != 'undefined'){
556                 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
557             }
558             
559             if(typeof(config.smHeader) != 'undefined'){
560                 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
561             }
562             
563             if(typeof(config.xsHeader) != 'undefined'){
564                 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
565             }
566             
567             if(hh.length){
568                 c.html = hh;
569             }
570             
571             if(typeof(config.tooltip) != 'undefined'){
572                 c.tooltip = config.tooltip;
573             }
574             
575             if(typeof(config.colspan) != 'undefined'){
576                 c.colspan = config.colspan;
577             }
578             
579             if(typeof(config.hidden) != 'undefined' && config.hidden){
580                 c.style += ' display:none;';
581             }
582             
583             if(typeof(config.dataIndex) != 'undefined'){
584                 c.sort = config.dataIndex;
585             }
586             
587             if(typeof(config.sortable) != 'undefined' && config.sortable){
588                 c.cls = 'sortable';
589             }
590             
591             if(typeof(config.align) != 'undefined' && config.align.length){
592                 c.style += ' text-align:' + config.align + ';';
593             }
594             
595             if(typeof(config.width) != 'undefined'){
596                 c.style += ' width:' + config.width + 'px;';
597             }
598             
599             if(typeof(config.cls) != 'undefined'){
600                 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
601             }
602             
603             ['xs','sm','md','lg'].map(function(size){
604                 
605                 if(typeof(config[size]) == 'undefined'){
606                     return;
607                 }
608                 
609                 if (!config[size]) { // 0 = hidden
610                     c.cls += ' hidden-' + size;
611                     return;
612                 }
613                 
614                 c.cls += ' col-' + size + '-' + config[size];
615
616             });
617             
618             header.cn.push(c)
619         }
620         
621         return header;
622     },
623     
624     renderBody : function()
625     {
626         var body = {
627             tag: 'tbody',
628             cn : [
629                 {
630                     tag: 'tr',
631                     cn : [
632                         {
633                             tag : 'td',
634                             colspan :  this.cm.getColumnCount()
635                         }
636                     ]
637                 }
638             ]
639         };
640         
641         return body;
642     },
643     
644     renderFooter : function()
645     {
646         var footer = {
647             tag: 'tfoot',
648             cn : [
649                 {
650                     tag: 'tr',
651                     cn : [
652                         {
653                             tag : 'td',
654                             colspan :  this.cm.getColumnCount()
655                         }
656                     ]
657                 }
658             ]
659         };
660         
661         return footer;
662     },
663     
664     
665     
666     onLoad : function()
667     {
668 //        Roo.log('ds onload');
669         this.clear();
670         
671         var _this = this;
672         var cm = this.cm;
673         var ds = this.store;
674         
675         Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
676             e.removeClass(['glyphicon', 'glyphicon-arrow-up', 'glyphicon-arrow-down']);
677             
678             if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
679                 e.addClass(['glyphicon', 'glyphicon-arrow-up']);
680             }
681             
682             if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
683                 e.addClass(['glyphicon', 'glyphicon-arrow-down']);
684             }
685         });
686         
687         var tbody =  this.mainBody;
688               
689         if(ds.getCount() > 0){
690             ds.data.each(function(d,rowIndex){
691                 var row =  this.renderRow(cm, ds, rowIndex);
692                 
693                 tbody.createChild(row);
694                 
695                 var _this = this;
696                 
697                 if(row.cellObjects.length){
698                     Roo.each(row.cellObjects, function(r){
699                         _this.renderCellObject(r);
700                     })
701                 }
702                 
703             }, this);
704         }
705         
706         Roo.each(this.el.select('tbody td', true).elements, function(e){
707             e.on('mouseover', _this.onMouseover, _this);
708         });
709         
710         Roo.each(this.el.select('tbody td', true).elements, function(e){
711             e.on('mouseout', _this.onMouseout, _this);
712         });
713         this.fireEvent('rowsrendered', this);
714         //if(this.loadMask){
715         //    this.maskEl.hide();
716         //}
717     },
718     
719     
720     onUpdate : function(ds,record)
721     {
722         this.refreshRow(record);
723     },
724     
725     onRemove : function(ds, record, index, isUpdate){
726         if(isUpdate !== true){
727             this.fireEvent("beforerowremoved", this, index, record);
728         }
729         var bt = this.mainBody.dom;
730         
731         var rows = this.el.select('tbody > tr', true).elements;
732         
733         if(typeof(rows[index]) != 'undefined'){
734             bt.removeChild(rows[index].dom);
735         }
736         
737 //        if(bt.rows[index]){
738 //            bt.removeChild(bt.rows[index]);
739 //        }
740         
741         if(isUpdate !== true){
742             //this.stripeRows(index);
743             //this.syncRowHeights(index, index);
744             //this.layout();
745             this.fireEvent("rowremoved", this, index, record);
746         }
747     },
748     
749     onAdd : function(ds, records, rowIndex)
750     {
751         //Roo.log('on Add called');
752         // - note this does not handle multiple adding very well..
753         var bt = this.mainBody.dom;
754         for (var i =0 ; i < records.length;i++) {
755             //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
756             //Roo.log(records[i]);
757             //Roo.log(this.store.getAt(rowIndex+i));
758             this.insertRow(this.store, rowIndex + i, false);
759             return;
760         }
761         
762     },
763     
764     
765     refreshRow : function(record){
766         var ds = this.store, index;
767         if(typeof record == 'number'){
768             index = record;
769             record = ds.getAt(index);
770         }else{
771             index = ds.indexOf(record);
772         }
773         this.insertRow(ds, index, true);
774         this.onRemove(ds, record, index+1, true);
775         //this.syncRowHeights(index, index);
776         //this.layout();
777         this.fireEvent("rowupdated", this, index, record);
778     },
779     
780     insertRow : function(dm, rowIndex, isUpdate){
781         
782         if(!isUpdate){
783             this.fireEvent("beforerowsinserted", this, rowIndex);
784         }
785             //var s = this.getScrollState();
786         var row = this.renderRow(this.cm, this.store, rowIndex);
787         // insert before rowIndex..
788         var e = this.mainBody.createChild(row,this.getRowDom(rowIndex));
789         
790         var _this = this;
791                 
792         if(row.cellObjects.length){
793             Roo.each(row.cellObjects, function(r){
794                 _this.renderCellObject(r);
795             })
796         }
797             
798         if(!isUpdate){
799             this.fireEvent("rowsinserted", this, rowIndex);
800             //this.syncRowHeights(firstRow, lastRow);
801             //this.stripeRows(firstRow);
802             //this.layout();
803         }
804         
805     },
806     
807     
808     getRowDom : function(rowIndex)
809     {
810         var rows = this.el.select('tbody > tr', true).elements;
811         
812         return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
813         
814     },
815     // returns the object tree for a tr..
816   
817     
818     renderRow : function(cm, ds, rowIndex) 
819     {
820         
821         var d = ds.getAt(rowIndex);
822         
823         var row = {
824             tag : 'tr',
825             cn : []
826         };
827             
828         var cellObjects = [];
829         
830         for(var i = 0, len = cm.getColumnCount(); i < len; i++){
831             var config = cm.config[i];
832             
833             var renderer = cm.getRenderer(i);
834             var value = '';
835             var id = false;
836             
837             if(typeof(renderer) !== 'undefined'){
838                 value = renderer(d.data[cm.getDataIndex(i)], false, d);
839             }
840             // if object are returned, then they are expected to be Roo.bootstrap.Component instances
841             // and are rendered into the cells after the row is rendered - using the id for the element.
842             
843             if(typeof(value) === 'object'){
844                 id = Roo.id();
845                 cellObjects.push({
846                     container : id,
847                     cfg : value 
848                 })
849             }
850             
851             var rowcfg = {
852                 record: d,
853                 rowIndex : rowIndex,
854                 colIndex : i,
855                 rowClass : ''
856             };
857
858             this.fireEvent('rowclass', this, rowcfg);
859             
860             var td = {
861                 tag: 'td',
862                 cls : rowcfg.rowClass,
863                 style: '',
864                 html: (typeof(value) === 'object') ? '' : value
865             };
866             
867             if (id) {
868                 td.id = id;
869             }
870             
871             if(typeof(config.colspan) != 'undefined'){
872                 td.colspan = config.colspan;
873             }
874             
875             if(typeof(config.hidden) != 'undefined' && config.hidden){
876                 td.style += ' display:none;';
877             }
878             
879             if(typeof(config.align) != 'undefined' && config.align.length){
880                 td.style += ' text-align:' + config.align + ';';
881             }
882             
883             if(typeof(config.width) != 'undefined'){
884                 td.style += ' width:' +  config.width + 'px;';
885             }
886             
887             if(typeof(config.cursor) != 'undefined'){
888                 td.style += ' cursor:' +  config.cursor + ';';
889             }
890             
891             if(typeof(config.cls) != 'undefined'){
892                 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
893             }
894             
895             ['xs','sm','md','lg'].map(function(size){
896                 
897                 if(typeof(config[size]) == 'undefined'){
898                     return;
899                 }
900                 
901                 if (!config[size]) { // 0 = hidden
902                     td.cls += ' hidden-' + size;
903                     return;
904                 }
905                 
906                 td.cls += ' col-' + size + '-' + config[size];
907
908             });
909              
910             row.cn.push(td);
911            
912         }
913         
914         row.cellObjects = cellObjects;
915         
916         return row;
917           
918     },
919     
920     
921     
922     onBeforeLoad : function()
923     {
924         //Roo.log('ds onBeforeLoad');
925         
926         //this.clear();
927         
928         //if(this.loadMask){
929         //    this.maskEl.show();
930         //}
931     },
932      /**
933      * Remove all rows
934      */
935     clear : function()
936     {
937         this.el.select('tbody', true).first().dom.innerHTML = '';
938     },
939     /**
940      * Show or hide a row.
941      * @param {Number} rowIndex to show or hide
942      * @param {Boolean} state hide
943      */
944     setRowVisibility : function(rowIndex, state)
945     {
946         var bt = this.mainBody.dom;
947         
948         var rows = this.el.select('tbody > tr', true).elements;
949         
950         if(typeof(rows[rowIndex]) == 'undefined'){
951             return;
952         }
953         rows[rowIndex].dom.style.display = state ? '' : 'none';
954     },
955     
956     
957     getSelectionModel : function(){
958         if(!this.selModel){
959             this.selModel = new Roo.bootstrap.Table.RowSelectionModel();
960         }
961         return this.selModel;
962     },
963     /*
964      * Render the Roo.bootstrap object from renderder
965      */
966     renderCellObject : function(r)
967     {
968         var _this = this;
969         
970         var t = r.cfg.render(r.container);
971         
972         if(r.cfg.cn){
973             Roo.each(r.cfg.cn, function(c){
974                 var child = {
975                     container: t.getChildContainer(),
976                     cfg: c
977                 };
978                 _this.renderCellObject(child);
979             })
980         }
981     },
982     
983     getRowIndex : function(row)
984     {
985         var rowIndex = -1;
986         
987         Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
988             if(el != row){
989                 return;
990             }
991             
992             rowIndex = index;
993         });
994         
995         return rowIndex;
996     }
997    
998 });
999
1000  
1001
1002