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
24 * @cfg {boolean} striped Should the rows be alternative striped
25 * @cfg {boolean} bordered Add borders to the table
26 * @cfg {boolean} hover Add hover highlighting
27 * @cfg {boolean} condensed Format condensed
28 * @cfg {boolean} responsive Format condensed
29 * @cfg {Boolean} loadMask (true|false) default false
31 * @cfg {Roo.bootstrap.PagingToolbar} footer a paging toolbar
36 * @param {Object} config The config object
39 Roo.bootstrap.Table = function(config){
40 Roo.bootstrap.Table.superclass.constructor.call(this, config);
43 this.selModel = Roo.factory(this.sm, Roo.bootstrap.Table);
44 this.sm = this.selModel;
45 this.sm.xmodule = this.xmodule || false;
47 if (this.cm && typeof(this.cm.config) == 'undefined') {
48 this.colModel = new Roo.grid.ColumnModel(this.cm);
49 this.cm = this.colModel;
50 this.cm.xmodule = this.xmodule || false;
53 this.store= Roo.factory(this.store, Roo.data);
55 this.ds.xmodule = this.xmodule || false;
58 if (this.footer && this.store) {
59 this.footer.dataSource = this.ds;
60 this.footer = Roo.factory(this.footer);
64 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component, {
87 getAutoCreate : function(){
88 var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
97 cfg.cls += ' table-striped';
100 cfg.cls += ' table-hover';
103 cfg.cls += ' table-bordered';
105 if (this.condensed) {
106 cfg.cls += ' table-condensed';
108 if (this.responsive) {
109 cfg.cls += ' table-responsive';
116 cfg.cls+= ' ' +this.cls;
119 // this lot should be simplifed...
122 cfg.align=this.align;
125 cfg.bgcolor=this.bgcolor;
128 cfg.border=this.border;
130 if (this.cellpadding) {
131 cfg.cellpadding=this.cellpadding;
133 if (this.cellspacing) {
134 cfg.cellspacing=this.cellspacing;
137 cfg.frame=this.frame;
140 cfg.rules=this.rules;
143 cfg.sortable=this.sortable;
146 cfg.summary=this.summary;
149 cfg.width=this.width;
152 if(this.store || this.cm){
153 cfg.cn.push(this.renderHeader());
154 cfg.cn.push(this.renderBody());
155 cfg.cn.push(this.renderFooter());
157 cfg.cls+= ' TableGrid';
163 // initTableGrid : function()
174 // for(var i = 0, len = cm.getColumnCount(); i < len; i++){
177 // html: cm.getColumnHeader(i)
188 initEvents : function()
190 if(!this.store || !this.cm){
194 Roo.log('initEvents with ds!!!!');
198 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
199 e.on('click', _this.sort, _this);
201 // this.maskEl = Roo.DomHelper.append(this.el.select('.TableGrid', true).first(), {tag: "div", cls:"x-dlg-mask"}, true);
202 // this.maskEl.enableDisplayMode("block");
203 // this.maskEl.show();
205 this.parent().el.setStyle('position', 'relative');
207 this.footer.parentId = this.id;
208 this.footer.onRender(this.el.select('tfoot tr td').first(), null);
212 // mask should be using Roo.bootstrap.Mask...
217 style: "text-align:center",
221 style: "background-color:white;width:50%;margin:100 auto; display:none",
225 src: Roo.rootURL + '/images/ux/lightbox/loading.gif'
236 this.maskEl = Roo.DomHelper.append(document.body, mark, true);
238 var size = this.parent().el.getSize();
240 this.maskEl.setSize(size.width, 300); // we will fix the height at the beginning...
242 this.maskEl.enableDisplayMode("block");
244 this.store.on('load', this.onLoad, this);
245 this.store.on('beforeload', this.onBeforeLoad, this);
247 // load should be trigger on render..
254 sort : function(e,el)
256 var col = Roo.get(el)
258 if(!col.hasClass('sortable')){
262 var sort = col.attr('sort');
265 if(col.hasClass('glyphicon-arrow-up')){
269 this.store.sortInfo = {field : sort, direction : dir};
274 renderHeader : function()
283 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
285 var config = cm.config[i];
287 if(typeof(config.hidden) != 'undefined' && config.hidden){
293 html: cm.getColumnHeader(i)
296 if(typeof(config.dataIndex) != 'undefined'){
297 c.sort = config.dataIndex;
300 if(typeof(config.sortable) != 'undefined' && config.sortable){
304 if(typeof(config.width) != 'undefined'){
305 c.style = 'width:' + config.width + 'px';
314 renderBody : function()
324 renderFooter : function()
346 Roo.log('ds onload');
351 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
352 e.removeClass(['glyphicon', 'glyphicon-arrow-up', 'glyphicon-arrow-down']);
354 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
355 e.addClass(['glyphicon', 'glyphicon-arrow-up']);
358 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
359 e.addClass(['glyphicon', 'glyphicon-arrow-down']);
363 var tbody = this.el.select('tbody', true).first();
367 if(this.store.getCount() > 0){
368 this.store.data.each(function(d){
374 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
375 var config = cm.config[i];
377 if(typeof(config.hidden) != 'undefined' && config.hidden){
381 var renderer = cm.getRenderer(i);
385 if(typeof(renderer) !== 'undefined'){
386 value = renderer(d.data[cm.getDataIndex(i)], false, d);
389 if(typeof(value) === 'object'){
399 html: (typeof(value) === 'object') ? '' : value
402 if(typeof(config.width) != 'undefined'){
403 td.style = 'width:' + config.width + 'px';
410 tbody.createChild(row);
418 Roo.each(renders, function(r){
419 _this.renderColumn(r);
428 onBeforeLoad : function()
430 Roo.log('ds onBeforeLoad');
441 this.el.select('tbody', true).first().dom.innerHTML = '';
444 getSelectionModel : function(){
446 this.selModel = new Roo.bootstrap.Table.RowSelectionModel();
448 return this.selModel;
451 renderColumn : function(r)
454 r.cfg.render(Roo.get(r.id));
457 Roo.each(r.cfg.cn, function(c){
462 _this.renderColumn(child);