2 * @class Roo.bootstrap.Table
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
9 var table = Roo.factory({
12 autoSizeColumns: true,
19 sortInfo : { direction : 'ASC', field: 'name' },
24 url : 'https://example.com/some.data.url.json'
29 fields : [ 'id', 'name', whatever' ],
36 xtype : 'ColumnModel',
40 dataIndex : 'is_in_group',
43 renderer : function(v, x , r) {
45 return String.format("{0}", v)
51 xtype : 'RowSelectionModel',
52 xns : Roo.bootstrap.Table
53 // you can add listeners to catch selection change here....
59 grid.render(Roo.get("some-div"));
62 Currently the Table uses multiple headers to try and handle XL / Medium etc... styling
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.
71 * @cfg {String} cls table class
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} footerColumns (true|false) generate tfoot with columns, 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()
95 * @cfg {Number} minColumnWidth default 50 pixels minimum column width
99 * @param {Object} config The config object
102 Roo.bootstrap.Table = function(config)
104 Roo.bootstrap.Table.superclass.constructor.call(this, config);
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;
112 this.view = this; // compat with grid.
114 this.sm = this.sm || {xtype: 'RowSelectionModel'};
117 this.selModel = Roo.factory(this.sm, Roo.grid);
118 this.sm = this.selModel;
119 this.sm.xmodule = this.xmodule || false;
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;
128 this.store= Roo.factory(this.store, Roo.data);
129 this.ds = this.store;
130 this.ds.xmodule = this.xmodule || false;
133 if (this.footer && this.store) {
134 this.footer.dataSource = this.ds;
135 this.footer = Roo.factory(this.footer);
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
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
159 "celldblclick" : true,
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
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
177 "rowdblclick" : true,
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
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
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.
206 * @event rowsrendered
207 * Fires when all the rows have been rendered
208 * @param {Roo.bootstrap.Table} this
210 'rowsrendered' : true,
213 * The raw contextmenu event for the entire grid.
214 * @param {Roo.EventObject} e
216 "contextmenu" : true,
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
224 "rowcontextmenu" : true,
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
233 "cellcontextmenu" : true,
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
241 "headercontextmenu" : true,
244 * The raw mousedown event for the entire grid.
245 * @param {Roo.EventObject} e
252 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component, {
268 footerColumns : false,
270 enableColumnResize: true,
271 disableAutoSize: false,
273 rowSelection : false,
274 cellSelection : false,
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?
286 container: false, // used by gridpanel...
292 auto_hide_footer : false,
294 view: false, // actually points to this..
296 getAutoCreate : function()
298 var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
305 // this get's auto added by panel.Grid
306 if (this.scrollBody) {
307 cfg.cls += ' table-body-fixed';
310 cfg.cls += ' table-striped';
314 cfg.cls += ' table-hover';
317 cfg.cls += ' table-bordered';
319 if (this.condensed) {
320 cfg.cls += ' table-condensed';
323 if (this.responsive) {
324 cfg.cls += ' table-responsive';
328 cfg.cls+= ' ' +this.cls;
334 cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
337 if(this.store || this.cm){
339 cfg.cn.push(this.renderHeader());
342 cfg.cn.push(this.renderBody());
344 if(this.footerShow || this.footerColumns){
345 cfg.cn.push(this.renderFooter());
348 // where does this come from?
349 //cfg.cls+= ' TableGrid';
352 return { cn : [ cfg ] };
355 initEvents : function()
357 if(!this.store || !this.cm){
361 this.selModel.initEvents();
365 //Roo.log('initEvents with ds!!!!');
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();
374 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
375 e.on('click', this.sort, this);
379 // why is this done????? = it breaks dialogs??
380 //this.parent().el.setStyle('position', 'relative');
384 this.footer.parentId = this.id;
385 this.footer.onRender(this.el.select('tfoot tr td').first(), null);
388 this.el.select('tfoot tr td').first().addClass('hide');
393 this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
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);
402 this.el.on("contextmenu", this.onContextMenu, this);
405 this.cm.on("headerchange", this.onHeaderChange, this);
406 this.cm.on("hiddenchange", this.onHiddenChange, this, arguments);
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);
413 // guessing mainbody will work - this relays usually caught by selmodel at present.
414 this.relayEvents(this.bodyEl, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
417 this.resizeProxy = Roo.get(document.body).createChild({ cls:"x-grid-resize-proxy", html: ' ' });
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..)
426 // Compatibility with grid - we implement all the view features at present.
434 if(this.disableAutoSize) {
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();
447 var cols = []; // visable cols.
449 for(var i = 0, len = cm.getColumnCount(); i < len; i++) {
450 var w = cm.getColumnWidth(i, false);
452 cols.push( { rel : false, abs : 0 });
456 cols.push( { rel : false, abs : w });
458 last = i; // not really..
461 var w = cm.getColumnWidth(i, sz);
466 cols.push( { rel : w, abs : false });
469 var avail = this.bodyEl.dom.clientWidth - total_abs;
471 var unitWidth = Math.floor(avail / total);
472 var rem = avail - (unitWidth * total);
474 var hidden, width, pos = 0 , splithide , left;
475 for(var i = 0, len = cm.getColumnCount(); i < len; i++) {
477 hidden = 'display:none;';
479 width = 'width:0px;';
485 // we can honour xs/sm/md/xl ?
486 var w = cols[i].rel == false ? cols[i].abs : (cols[i].rel * unitWidth);
488 hidden = 'display:none;';
490 // width should return a small number...
492 w+=rem; // add the remaining with..
495 left = "left:" + (pos -4) + "px;";
496 width = "width:" + w+ "px;";
499 if (this.responsive) {
502 hidden = cm.isHidden(i) ? 'display:none;' : '';
503 splithide = 'display: none;';
506 styles.push( '#' , this.id , ' .x-col-' , i, " {", cm.config[i].css, width, hidden, "}\n" );
509 splithide = 'display:none;';
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"
520 //Roo.log(styles.join(''));
521 this.CSS.createStyleSheet( styles.join(''), this.id + '-cssrules');
527 onContextMenu : function(e, t)
529 this.processEvent("contextmenu", e);
532 processEvent : function(name, e)
534 if (name != 'touchstart' ) {
535 this.fireEvent(name, e);
538 var t = e.getTarget();
540 var cell = Roo.get(t);
546 if(cell.findParent('tfoot', false, true)){
550 if(cell.findParent('thead', false, true)){
552 if(e.getTarget().nodeName.toLowerCase() != 'th'){
553 cell = Roo.get(t).findParent('th', false, true);
555 Roo.log("failed to find th in thead?");
556 Roo.log(e.getTarget());
561 var cellIndex = cell.dom.cellIndex;
563 var ename = name == 'touchstart' ? 'click' : name;
564 this.fireEvent("header" + ename, this, cellIndex, e);
569 if(e.getTarget().nodeName.toLowerCase() != 'td'){
570 cell = Roo.get(t).findParent('td', false, true);
572 Roo.log("failed to find th in tbody?");
573 Roo.log(e.getTarget());
578 var row = cell.findParent('tr', false, true);
579 var cellIndex = cell.dom.cellIndex;
580 var rowIndex = row.dom.rowIndex - 1;
584 this.fireEvent("row" + name, this, rowIndex, e);
588 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
594 onMouseover : function(e, el)
596 var cell = Roo.get(el);
602 if(e.getTarget().nodeName.toLowerCase() != 'td'){
603 cell = cell.findParent('td', false, true);
606 var row = cell.findParent('tr', false, true);
607 var cellIndex = cell.dom.cellIndex;
608 var rowIndex = row.dom.rowIndex - 1; // start from 0
610 this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
614 onMouseout : function(e, el)
616 var cell = Roo.get(el);
622 if(e.getTarget().nodeName.toLowerCase() != 'td'){
623 cell = cell.findParent('td', false, true);
626 var row = cell.findParent('tr', false, true);
627 var cellIndex = cell.dom.cellIndex;
628 var rowIndex = row.dom.rowIndex - 1; // start from 0
630 this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
634 onClick : function(e, el)
636 var cell = Roo.get(el);
638 if(!cell || (!this.cellSelection && !this.rowSelection)){
642 if(e.getTarget().nodeName.toLowerCase() != 'td'){
643 cell = cell.findParent('td', false, true);
646 if(!cell || typeof(cell) == 'undefined'){
650 var row = cell.findParent('tr', false, true);
652 if(!row || typeof(row) == 'undefined'){
656 var cellIndex = cell.dom.cellIndex;
657 var rowIndex = this.getRowIndex(row);
659 // why??? - should these not be based on SelectionModel?
660 //if(this.cellSelection){
661 this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
664 //if(this.rowSelection){
665 this.fireEvent('rowclick', this, row, rowIndex, e);
670 onDblClick : function(e,el)
672 var cell = Roo.get(el);
674 if(!cell || (!this.cellSelection && !this.rowSelection)){
678 if(e.getTarget().nodeName.toLowerCase() != 'td'){
679 cell = cell.findParent('td', false, true);
682 if(!cell || typeof(cell) == 'undefined'){
686 var row = cell.findParent('tr', false, true);
688 if(!row || typeof(row) == 'undefined'){
692 var cellIndex = cell.dom.cellIndex;
693 var rowIndex = this.getRowIndex(row);
695 if(this.cellSelection){
696 this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
699 if(this.rowSelection){
700 this.fireEvent('rowdblclick', this, row, rowIndex, e);
703 findRowIndex : function(el)
705 var cell = Roo.get(el);
709 var row = cell.findParent('tr', false, true);
711 if(!row || typeof(row) == 'undefined'){
714 return this.getRowIndex(row);
716 sort : function(e,el)
718 var col = Roo.get(el);
720 if(!col.hasClass('sortable')){
724 var sort = col.attr('sort');
727 if(col.select('i', true).first().hasClass('fa-arrow-up')){
731 this.store.sortInfo = {field : sort, direction : dir};
734 Roo.log("calling footer first");
735 this.footer.onClick('first');
738 this.store.load({ params : { start : 0 } });
742 renderHeader : function()
752 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
754 var config = cm.config[i];
761 html: cm.getColumnHeader(i)
764 var tooltip = cm.getColumnTooltip(i);
772 if(typeof(config.sortable) != 'undefined' && config.sortable){
773 c.cls += ' sortable';
774 c.html = '<i class="fa"></i>' + c.html;
777 // could use BS4 hidden-..-down
779 if(typeof(config.lgHeader) != 'undefined'){
780 hh += '<span class="hidden-xs hidden-sm hidden-md ">' + config.lgHeader + '</span>';
783 if(typeof(config.mdHeader) != 'undefined'){
784 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
787 if(typeof(config.smHeader) != 'undefined'){
788 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
791 if(typeof(config.xsHeader) != 'undefined'){
792 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
799 if(typeof(config.tooltip) != 'undefined'){
800 c.tooltip = config.tooltip;
803 if(typeof(config.colspan) != 'undefined'){
804 c.colspan = config.colspan;
807 // hidden is handled by CSS now
809 if(typeof(config.dataIndex) != 'undefined'){
810 c.sort = config.dataIndex;
815 if(typeof(config.align) != 'undefined' && config.align.length){
816 c.style += ' text-align:' + config.align + ';';
819 /* width is done in CSS
820 *if(typeof(config.width) != 'undefined'){
821 c.style += ' width:' + config.width + 'px;';
822 this.totalWidth += config.width;
824 this.totalWidth += 100; // assume minimum of 100 per column?
828 if(typeof(config.cls) != 'undefined'){
829 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
831 // this is the bit that doesnt reall work at all...
833 if (this.responsive) {
836 ['xs','sm','md','lg'].map(function(size){
838 if(typeof(config[size]) == 'undefined'){
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';
848 c.cls += ' col-' + size + '-' + config[size] + (
849 size == 'xs' ? (' col-' + config[size] ) : '' // bs4 col-{num} replaces col-xs
857 c.html +=' <span class="x-grid-split x-grid-split-' + i + '"></span>';
868 renderBody : function()
878 colspan : this.cm.getColumnCount()
888 renderFooter : function()
898 colspan : this.cm.getColumnCount()
910 // Roo.log('ds onload');
917 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
918 e.select('i', true).removeClass(['fa-arrow-up', 'fa-arrow-down']);
919 if (_this.store.sortInfo) {
921 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
922 e.select('i', true).addClass(['fa-arrow-up']);
925 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
926 e.select('i', true).addClass(['fa-arrow-down']);
931 var tbody = this.bodyEl;
933 if(ds.getCount() > 0){
934 ds.data.each(function(d,rowIndex){
935 var row = this.renderRow(cm, ds, rowIndex);
937 tbody.createChild(row);
941 if(row.cellObjects.length){
942 Roo.each(row.cellObjects, function(r){
943 _this.renderCellObject(r);
948 } else if (this.empty_results.length) {
949 this.el.mask(this.empty_results, 'no-spinner');
952 var tfoot = this.el.select('tfoot', true).first();
954 if(this.footerShow && this.auto_hide_footer && this.mainFoot){
956 this.mainFoot.setVisibilityMode(Roo.Element.DISPLAY).hide();
958 var total = this.ds.getTotalCount();
960 if(this.footer.pageSize < total){
961 this.mainFoot.show();
965 if(!this.footerShow && this.summaryFooterShow) {
972 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
975 cls : ' x-fcol-' + i,
976 html: cm.config[i].summaryFooter
983 tfoot.dom.innerHTML = '';
985 tfoot.createChild(tr);
988 Roo.each(this.el.select('tbody td', true).elements, function(e){
989 e.on('mouseover', _this.onMouseover, _this);
992 Roo.each(this.el.select('tbody td', true).elements, function(e){
993 e.on('mouseout', _this.onMouseout, _this);
995 this.fireEvent('rowsrendered', this);
999 this.initCSS(); /// resize cols
1005 onUpdate : function(ds,record)
1007 this.refreshRow(record);
1011 onRemove : function(ds, record, index, isUpdate){
1012 if(isUpdate !== true){
1013 this.fireEvent("beforerowremoved", this, index, record);
1015 var bt = this.bodyEl.dom;
1017 var rows = this.el.select('tbody > tr', true).elements;
1019 if(typeof(rows[index]) != 'undefined'){
1020 bt.removeChild(rows[index].dom);
1023 // if(bt.rows[index]){
1024 // bt.removeChild(bt.rows[index]);
1027 if(isUpdate !== true){
1028 //this.stripeRows(index);
1029 //this.syncRowHeights(index, index);
1031 this.fireEvent("rowremoved", this, index, record);
1035 onAdd : function(ds, records, rowIndex)
1037 //Roo.log('on Add called');
1038 // - note this does not handle multiple adding very well..
1039 var bt = this.bodyEl.dom;
1040 for (var i =0 ; i < records.length;i++) {
1041 //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
1042 //Roo.log(records[i]);
1043 //Roo.log(this.store.getAt(rowIndex+i));
1044 this.insertRow(this.store, rowIndex + i, false);
1051 refreshRow : function(record){
1052 var ds = this.store, index;
1053 if(typeof record == 'number'){
1055 record = ds.getAt(index);
1057 index = ds.indexOf(record);
1059 return; // should not happen - but seems to
1062 this.insertRow(ds, index, true);
1064 this.onRemove(ds, record, index+1, true);
1066 //this.syncRowHeights(index, index);
1068 this.fireEvent("rowupdated", this, index, record);
1070 // private - called by RowSelection
1071 onRowSelect : function(rowIndex){
1072 var row = this.getRowDom(rowIndex);
1073 row.addClass(['bg-info','info']);
1075 // private - called by RowSelection
1076 onRowDeselect : function(rowIndex)
1081 var row = this.getRowDom(rowIndex);
1082 row.removeClass(['bg-info','info']);
1085 * Focuses the specified row.
1086 * @param {Number} row The row index
1088 focusRow : function(row)
1090 //Roo.log('GridView.focusRow');
1091 var x = this.bodyEl.dom.scrollLeft;
1092 this.focusCell(row, 0, false);
1093 this.bodyEl.dom.scrollLeft = x;
1097 * Focuses the specified cell.
1098 * @param {Number} row The row index
1099 * @param {Number} col The column index
1100 * @param {Boolean} hscroll false to disable horizontal scrolling
1102 focusCell : function(row, col, hscroll)
1104 //Roo.log('GridView.focusCell');
1105 var el = this.ensureVisible(row, col, hscroll);
1106 // not sure what focusEL achives = it's a <a> pos relative
1107 //this.focusEl.alignTo(el, "tl-tl");
1109 // this.focusEl.focus();
1111 // this.focusEl.focus.defer(1, this.focusEl);
1116 * Scrolls the specified cell into view
1117 * @param {Number} row The row index
1118 * @param {Number} col The column index
1119 * @param {Boolean} hscroll false to disable horizontal scrolling
1121 ensureVisible : function(row, col, hscroll)
1123 //Roo.log('GridView.ensureVisible,' + row + ',' + col);
1124 //return null; //disable for testing.
1125 if(typeof row != "number"){
1128 if(row < 0 && row >= this.ds.getCount()){
1131 col = (col !== undefined ? col : 0);
1133 while(cm.isHidden(col)){
1137 var el = this.getCellDom(row, col);
1141 var c = this.bodyEl.dom;
1143 var ctop = parseInt(el.offsetTop, 10);
1144 var cleft = parseInt(el.offsetLeft, 10);
1145 var cbot = ctop + el.offsetHeight;
1146 var cright = cleft + el.offsetWidth;
1148 //var ch = c.clientHeight - this.mainHd.dom.offsetHeight;
1149 var ch = 0; //?? header is not withing the area?
1150 var stop = parseInt(c.scrollTop, 10);
1151 var sleft = parseInt(c.scrollLeft, 10);
1152 var sbot = stop + ch;
1153 var sright = sleft + c.clientWidth;
1155 Roo.log('GridView.ensureVisible:' +
1157 ' c.clientHeight:' + c.clientHeight +
1158 ' this.mainHd.dom.offsetHeight:' + this.mainHd.dom.offsetHeight +
1167 //Roo.log("set scrolltop to ctop DISABLE?");
1168 }else if(cbot > sbot){
1169 //Roo.log("set scrolltop to cbot-ch");
1170 c.scrollTop = cbot-ch;
1173 if(hscroll !== false){
1175 c.scrollLeft = cleft;
1176 }else if(cright > sright){
1177 c.scrollLeft = cright-c.clientWidth;
1185 insertRow : function(dm, rowIndex, isUpdate){
1188 this.fireEvent("beforerowsinserted", this, rowIndex);
1190 //var s = this.getScrollState();
1191 var row = this.renderRow(this.cm, this.store, rowIndex);
1192 // insert before rowIndex..
1193 var e = this.bodyEl.createChild(row,this.getRowDom(rowIndex));
1197 if(row.cellObjects.length){
1198 Roo.each(row.cellObjects, function(r){
1199 _this.renderCellObject(r);
1204 this.fireEvent("rowsinserted", this, rowIndex);
1205 //this.syncRowHeights(firstRow, lastRow);
1206 //this.stripeRows(firstRow);
1213 getRowDom : function(rowIndex)
1215 var rows = this.el.select('tbody > tr', true).elements;
1217 return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
1220 getCellDom : function(rowIndex, colIndex)
1222 var row = this.getRowDom(rowIndex);
1223 if (row === false) {
1226 var cols = row.select('td', true).elements;
1227 return (typeof(cols[colIndex]) == 'undefined') ? false : cols[colIndex];
1231 // returns the object tree for a tr..
1234 renderRow : function(cm, ds, rowIndex)
1236 var d = ds.getAt(rowIndex);
1240 cls : 'x-row-' + rowIndex,
1244 var cellObjects = [];
1246 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
1247 var config = cm.config[i];
1249 var renderer = cm.getRenderer(i);
1253 if(typeof(renderer) !== 'undefined'){
1254 value = renderer(d.data[cm.getDataIndex(i)], false, d);
1256 // if object are returned, then they are expected to be Roo.bootstrap.Component instances
1257 // and are rendered into the cells after the row is rendered - using the id for the element.
1259 if(typeof(value) === 'object'){
1269 rowIndex : rowIndex,
1274 this.fireEvent('rowclass', this, rowcfg);
1278 // this might end up displaying HTML?
1279 // this is too messy... - better to only do it on columsn you know are going to be too long
1280 //tooltip : (typeof(value) === 'object') ? '' : value,
1281 cls : rowcfg.rowClass + ' x-col-' + i,
1283 html: (typeof(value) === 'object') ? '' : value
1290 if(typeof(config.colspan) != 'undefined'){
1291 td.colspan = config.colspan;
1296 if(typeof(config.align) != 'undefined' && config.align.length){
1297 td.style += ' text-align:' + config.align + ';';
1299 if(typeof(config.valign) != 'undefined' && config.valign.length){
1300 td.style += ' vertical-align:' + config.valign + ';';
1303 if(typeof(config.width) != 'undefined'){
1304 td.style += ' width:' + config.width + 'px;';
1308 if(typeof(config.cursor) != 'undefined'){
1309 td.style += ' cursor:' + config.cursor + ';';
1312 if(typeof(config.cls) != 'undefined'){
1313 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
1315 if (this.responsive) {
1316 ['xs','sm','md','lg'].map(function(size){
1318 if(typeof(config[size]) == 'undefined'){
1324 if (!config[size]) { // 0 = hidden
1325 // BS 4 '0' is treated as hide that column and below.
1326 td.cls += ' hidden-' + size + ' hidden' + size + '-down';
1330 td.cls += ' col-' + size + '-' + config[size] + (
1331 size == 'xs' ? (' col-' + config[size] ) : '' // bs4 col-{num} replaces col-xs
1341 row.cellObjects = cellObjects;
1349 onBeforeLoad : function()
1351 this.el.unmask(); // if needed.
1358 this.el.select('tbody', true).first().dom.innerHTML = '';
1361 * Show or hide a row.
1362 * @param {Number} rowIndex to show or hide
1363 * @param {Boolean} state hide
1365 setRowVisibility : function(rowIndex, state)
1367 var bt = this.bodyEl.dom;
1369 var rows = this.el.select('tbody > tr', true).elements;
1371 if(typeof(rows[rowIndex]) == 'undefined'){
1374 rows[rowIndex][ state ? 'removeClass' : 'addClass']('d-none');
1379 getSelectionModel : function(){
1381 this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
1383 return this.selModel;
1386 * Render the Roo.bootstrap object from renderder
1388 renderCellObject : function(r)
1392 r.cfg.parentId = (typeof(r.container) == 'string') ? r.container : r.container.id;
1394 var t = r.cfg.render(r.container);
1397 Roo.each(r.cfg.cn, function(c){
1399 container: t.getChildContainer(),
1402 _this.renderCellObject(child);
1407 * get the Row Index from a dom element.
1408 * @param {Roo.Element} row The row to look for
1409 * @returns {Number} the row
1411 getRowIndex : function(row)
1415 Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
1426 * get the header TH element for columnIndex
1427 * @param {Number} columnIndex
1428 * @returns {Roo.Element}
1430 getHeaderIndex: function(colIndex)
1432 var cols = this.headEl.select('th', true).elements;
1433 return cols[colIndex];
1436 * get the Column Index from a dom element. (using regex on x-hcol-{colid})
1437 * @param {domElement} cell to look for
1438 * @returns {Number} the column
1440 getCellIndex : function(cell)
1442 var id = String(cell.className).match(Roo.bootstrap.Table.cellRE);
1444 return parseInt(id[1], 10);
1449 * Returns the grid's underlying element = used by panel.Grid
1450 * @return {Element} The element
1452 getGridEl : function(){
1456 * Forces a resize - used by panel.Grid
1457 * @return {Element} The element
1459 autoSize : function()
1461 if(this.disableAutoSize) {
1464 //var ctr = Roo.get(this.container.dom.parentElement);
1465 var ctr = Roo.get(this.el.dom);
1467 var thd = this.getGridEl().select('thead',true).first();
1468 var tbd = this.getGridEl().select('tbody', true).first();
1469 var tfd = this.getGridEl().select('tfoot', true).first();
1471 var cw = ctr.getWidth();
1472 this.getGridEl().select('tfoot tr, tfoot td',true).setWidth(cw);
1476 tbd.setWidth(ctr.getWidth());
1477 // if the body has a max height - and then scrolls - we should perhaps set up the height here
1478 // this needs fixing for various usage - currently only hydra job advers I think..
1480 // ctr.getHeight() - ((thd ? thd.getHeight() : 0) + (tfd ? tfd.getHeight() : 0))
1482 var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
1485 cw = Math.max(cw, this.totalWidth);
1486 this.getGridEl().select('tbody tr',true).setWidth(cw);
1489 // resize 'expandable coloumn?
1491 return; // we doe not have a view in this design..
1494 onBodyScroll: function()
1496 //Roo.log("body scrolled');" + this.bodyEl.dom.scrollLeft);
1498 this.headEl.setStyle({
1499 'position' : 'relative',
1500 'left': (-1* this.bodyEl.dom.scrollLeft) + 'px'
1506 var scrollHeight = this.bodyEl.dom.scrollHeight;
1508 var scrollTop = Math.ceil(this.bodyEl.getScroll().top);
1510 var height = this.bodyEl.getHeight();
1512 if(scrollHeight - height == scrollTop) {
1514 var total = this.ds.getTotalCount();
1516 if(this.footer.cursor + this.footer.pageSize < total){
1518 this.footer.ds.load({
1520 start : this.footer.cursor + this.footer.pageSize,
1521 limit : this.footer.pageSize
1530 onColumnSplitterMoved : function(i, diff)
1532 this.userResized = true;
1534 var cm = this.colModel;
1536 var w = this.getHeaderIndex(i).getWidth() + diff;
1539 cm.setColumnWidth(i, w, true);
1541 //var cid = cm.getColumnId(i); << not used in this version?
1542 /* Roo.log(['#' + this.id + ' .x-col-' + i, "width", w + "px"]);
1544 this.CSS.updateRule( '#' + this.id + ' .x-col-' + i, "width", w + "px");
1545 this.CSS.updateRule('#' + this.id + ' .x-hcol-' + i, "width", w + "px");
1546 this.CSS.updateRule('#' + this.id + ' .x-grid-split-' + i, "left", w + "px");
1548 //this.updateSplitters();
1549 //this.layout(); << ??
1550 this.fireEvent("columnresize", i, w);
1552 onHeaderChange : function()
1554 var header = this.renderHeader();
1555 var table = this.el.select('table', true).first();
1557 this.headEl.remove();
1558 this.headEl = table.createChild(header, this.bodyEl, false);
1560 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
1561 e.on('click', this.sort, this);
1564 if(this.enableColumnResize !== false && Roo.grid.SplitDragZone){
1565 new Roo.grid.SplitDragZone(this, this.headEl.dom, false); // not sure what 'lockedHd is for this implementation..)
1570 onHiddenChange : function(colModel, colIndex, hidden)
1574 var thSelector = '#' + this.id + ' .x-hcol-' + colIndex;
1575 var tdSelector = '#' + this.id + ' .x-col-' + colIndex;
1577 this.CSS.updateRule(thSelector, "display", "");
1578 this.CSS.updateRule(tdSelector, "display", "");
1581 this.CSS.updateRule(thSelector, "display", "none");
1582 this.CSS.updateRule(tdSelector, "display", "none");
1585 // onload calls initCSS()
1586 this.onHeaderChange();
1590 setColumnWidth: function(col_index, width)
1592 // width = "md-2 xs-2..."
1593 if(!this.colModel.config[col_index]) {
1597 var w = width.split(" ");
1599 var rows = this.el.dom.getElementsByClassName("x-col-"+col_index);
1601 var h_row = this.el.dom.getElementsByClassName("x-hcol-"+col_index);
1604 for(var j = 0; j < w.length; j++) {
1610 var size_cls = w[j].split("-");
1612 if(!Number.isInteger(size_cls[1] * 1)) {
1616 if(!this.colModel.config[col_index][size_cls[0]]) {
1620 if(!h_row[0].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
1624 h_row[0].classList.replace(
1625 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
1626 "col-"+size_cls[0]+"-"+size_cls[1]
1629 for(var i = 0; i < rows.length; i++) {
1631 var size_cls = w[j].split("-");
1633 if(!Number.isInteger(size_cls[1] * 1)) {
1637 if(!this.colModel.config[col_index][size_cls[0]]) {
1641 if(!rows[i].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
1645 rows[i].classList.replace(
1646 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
1647 "col-"+size_cls[0]+"-"+size_cls[1]
1651 this.colModel.config[col_index][size_cls[0]] = size_cls[1];
1656 // currently only used to find the split on drag..
1657 Roo.bootstrap.Table.cellRE = /(?:.*?)x-grid-(?:hd|cell|split)-([\d]+)(?:.*?)/;
1662 Roo.bootstrap.Table.AbstractSelectionModel = Roo.grid.AbstractSelectionModel;
1663 Roo.bootstrap.Table.RowSelectionModel = Roo.grid.RowSelectionModel;