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} headerShow (true|false) generate thead, default true
84 * @cfg {Boolean} rowSelection (true|false) default false
85 * @cfg {Boolean} cellSelection (true|false) default false
86 * @cfg {Boolean} scrollBody (true|false) default false - body scrolled / fixed header (with resizable columns)
87 * @cfg {Roo.bootstrap.PagingToolbar} footer a paging toolbar
88 * @cfg {Boolean} lazyLoad auto load data while scrolling to the end (default false)
89 * @cfg {Boolean} auto_hide_footer auto hide footer if only one page (default false)
90 * @cfg {Boolean} enableColumnResize default true if columns can be resized = needs scrollBody to be set to work (drag/drop)
91 * @cfg {Boolean} disableAutoSize disable auto size
94 * @cfg {Number} minColumnWidth default 50 pixels minimum column width
98 * @param {Object} config The config object
101 Roo.bootstrap.Table = function(config)
103 Roo.bootstrap.Table.superclass.constructor.call(this, config);
106 this.rowSelection = (typeof(config.rowSelection) != 'undefined') ? config.rowSelection : this.rowSelection;
107 this.cellSelection = (typeof(config.cellSelection) != 'undefined') ? config.cellSelection : this.cellSelection;
108 this.headerShow = (typeof(config.thead) != 'undefined') ? config.thead : this.headerShow;
109 this.footerShow = (typeof(config.tfoot) != 'undefined') ? config.tfoot : this.footerShow;
111 this.view = this; // compat with grid.
113 this.sm = this.sm || {xtype: 'RowSelectionModel'};
116 this.selModel = Roo.factory(this.sm, Roo.grid);
117 this.sm = this.selModel;
118 this.sm.xmodule = this.xmodule || false;
121 if (this.cm && typeof(this.cm.config) == 'undefined') {
122 this.colModel = new Roo.grid.ColumnModel(this.cm);
123 this.cm = this.colModel;
124 this.cm.xmodule = this.xmodule || false;
127 this.store= Roo.factory(this.store, Roo.data);
128 this.ds = this.store;
129 this.ds.xmodule = this.xmodule || false;
132 if (this.footer && this.store) {
133 this.footer.dataSource = this.ds;
134 this.footer = Roo.factory(this.footer);
141 * Fires when a cell is clicked
142 * @param {Roo.bootstrap.Table} this
143 * @param {Roo.Element} el
144 * @param {Number} rowIndex
145 * @param {Number} columnIndex
146 * @param {Roo.EventObject} e
150 * @event celldblclick
151 * Fires when a cell is double clicked
152 * @param {Roo.bootstrap.Table} this
153 * @param {Roo.Element} el
154 * @param {Number} rowIndex
155 * @param {Number} columnIndex
156 * @param {Roo.EventObject} e
158 "celldblclick" : true,
161 * Fires when a row is clicked
162 * @param {Roo.bootstrap.Table} this
163 * @param {Roo.Element} el
164 * @param {Number} rowIndex
165 * @param {Roo.EventObject} e
170 * Fires when a row is double clicked
171 * @param {Roo.bootstrap.Table} this
172 * @param {Roo.Element} el
173 * @param {Number} rowIndex
174 * @param {Roo.EventObject} e
176 "rowdblclick" : true,
179 * Fires when a mouseover occur
180 * @param {Roo.bootstrap.Table} this
181 * @param {Roo.Element} el
182 * @param {Number} rowIndex
183 * @param {Number} columnIndex
184 * @param {Roo.EventObject} e
189 * Fires when a mouseout occur
190 * @param {Roo.bootstrap.Table} this
191 * @param {Roo.Element} el
192 * @param {Number} rowIndex
193 * @param {Number} columnIndex
194 * @param {Roo.EventObject} e
199 * Fires when a row is rendered, so you can change add a style to it.
200 * @param {Roo.bootstrap.Table} this
201 * @param {Object} rowcfg contains record rowIndex colIndex and rowClass - set rowClass to add a style.
205 * @event rowsrendered
206 * Fires when all the rows have been rendered
207 * @param {Roo.bootstrap.Table} this
209 'rowsrendered' : true,
212 * The raw contextmenu event for the entire grid.
213 * @param {Roo.EventObject} e
215 "contextmenu" : true,
217 * @event rowcontextmenu
218 * Fires when a row is right clicked
219 * @param {Roo.bootstrap.Table} this
220 * @param {Number} rowIndex
221 * @param {Roo.EventObject} e
223 "rowcontextmenu" : true,
225 * @event cellcontextmenu
226 * Fires when a cell is right clicked
227 * @param {Roo.bootstrap.Table} this
228 * @param {Number} rowIndex
229 * @param {Number} cellIndex
230 * @param {Roo.EventObject} e
232 "cellcontextmenu" : true,
234 * @event headercontextmenu
235 * Fires when a header is right clicked
236 * @param {Roo.bootstrap.Table} this
237 * @param {Number} columnIndex
238 * @param {Roo.EventObject} e
240 "headercontextmenu" : true,
243 * The raw mousedown event for the entire grid.
244 * @param {Roo.EventObject} e
251 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component, {
268 enableColumnResize: true,
269 disableAutoSize: false,
271 rowSelection : false,
272 cellSelection : false,
277 // Roo.Element - the tbody
278 bodyEl: false, // <tbody> Roo.Element - thead element
279 headEl: false, // <thead> Roo.Element - thead element
280 resizeProxy : false, // proxy element for dragging?
284 container: false, // used by gridpanel...
290 auto_hide_footer : false,
292 view: false, // actually points to this..
294 getAutoCreate : function()
296 var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
303 // this get's auto added by panel.Grid
304 if (this.scrollBody) {
305 cfg.cls += ' table-body-fixed';
308 cfg.cls += ' table-striped';
312 cfg.cls += ' table-hover';
315 cfg.cls += ' table-bordered';
317 if (this.condensed) {
318 cfg.cls += ' table-condensed';
321 if (this.responsive) {
322 cfg.cls += ' table-responsive';
326 cfg.cls+= ' ' +this.cls;
332 cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
335 if(this.store || this.cm){
337 cfg.cn.push(this.renderHeader());
340 cfg.cn.push(this.renderBody());
343 cfg.cn.push(this.renderFooter());
345 // where does this come from?
346 //cfg.cls+= ' TableGrid';
349 return { cn : [ cfg ] };
352 initEvents : function()
354 if(!this.store || !this.cm){
358 this.selModel.initEvents();
362 //Roo.log('initEvents with ds!!!!');
364 this.bodyEl = this.el.select('tbody', true).first();
365 this.headEl = this.el.select('thead', true).first();
366 this.mainFoot = this.el.select('tfoot', true).first();
371 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
372 e.on('click', this.sort, this);
376 // why is this done????? = it breaks dialogs??
377 //this.parent().el.setStyle('position', 'relative');
381 this.footer.parentId = this.id;
382 this.footer.onRender(this.el.select('tfoot tr td').first(), null);
385 this.el.select('tfoot tr td').first().addClass('hide');
390 this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
393 this.store.on('load', this.onLoad, this);
394 this.store.on('beforeload', this.onBeforeLoad, this);
395 this.store.on('update', this.onUpdate, this);
396 this.store.on('add', this.onAdd, this);
397 this.store.on("clear", this.clear, this);
399 this.el.on("contextmenu", this.onContextMenu, this);
402 this.cm.on("headerchange", this.onHeaderChange, this);
403 this.cm.on("hiddenchange", this.onHiddenChange, this, arguments);
405 //?? does bodyEl get replaced on render?
406 this.bodyEl.on("click", this.onClick, this);
407 this.bodyEl.on("dblclick", this.onDblClick, this);
408 this.bodyEl.on('scroll', this.onBodyScroll, this);
410 // guessing mainbody will work - this relays usually caught by selmodel at present.
411 this.relayEvents(this.bodyEl, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
414 this.resizeProxy = Roo.get(document.body).createChild({ cls:"x-grid-resize-proxy", html: ' ' });
417 if(this.headEl && this.enableColumnResize !== false && Roo.grid.SplitDragZone){
418 new Roo.grid.SplitDragZone(this, this.headEl.dom, false); // not sure what 'lockedHd is for this implementation..)
423 // Compatibility with grid - we implement all the view features at present.
431 if(this.disableAutoSize) {
432 Roo.log("DISABLEINITCSS");
436 var cm = this.cm, styles = [];
437 this.CSS.removeStyleSheet(this.id + '-cssrules');
438 var headHeight = this.headEl ? this.headEl.dom.clientHeight : 0;
439 // we can honour xs/sm/md/xl as widths...
440 // we first have to decide what widht we are currently at...
441 var sz = Roo.getGridSize();
445 var cols = []; // visable cols.
447 for(var i = 0, len = cm.getColumnCount(); i < len; i++) {
448 var w = cm.getColumnWidth(i, false);
450 cols.push( { rel : false, abs : 0 });
454 cols.push( { rel : false, abs : w });
456 last = i; // not really..
459 var w = cm.getColumnWidth(i, sz);
464 cols.push( { rel : w, abs : false });
467 var avail = this.bodyEl.dom.clientWidth - total_abs;
469 var unitWidth = Math.floor(avail / total);
470 var rem = avail - (unitWidth * total);
472 var hidden, width, pos = 0 , splithide , left;
473 for(var i = 0, len = cm.getColumnCount(); i < len; i++) {
475 hidden = 'display:none;';
477 width = 'width:0px;';
483 // we can honour xs/sm/md/xl ?
484 var w = cols[i].rel == false ? cols[i].abs : (cols[i].rel * unitWidth);
486 hidden = 'display:none;';
488 // width should return a small number...
490 w+=rem; // add the remaining with..
493 left = "left:" + (pos -4) + "px;";
494 width = "width:" + w+ "px;";
497 if (this.responsive) {
500 hidden = cm.isHidden(i) ? 'display:none;' : '';
501 splithide = 'display: none;';
504 styles.push( '#' , this.id , ' .x-col-' , i, " {", cm.config[i].css, width, hidden, "}\n" );
507 splithide = 'display:none;';
510 styles.push('#' , this.id , ' .x-hcol-' , i, " { ", width, hidden," }\n",
511 '#' , this.id , ' .x-grid-split-' , i, " { ", left, splithide, 'height:', (headHeight - 4), "px;}\n",
512 // this is the popover version..
513 '.popover-inner #' , this.id , ' .x-grid-split-' , i, " { ", left, splithide, 'height:', 100, "%;}\n"
518 //Roo.log(styles.join(''));
519 this.CSS.createStyleSheet( styles.join(''), this.id + '-cssrules');
525 onContextMenu : function(e, t)
527 this.processEvent("contextmenu", e);
530 processEvent : function(name, e)
532 if (name != 'touchstart' ) {
533 this.fireEvent(name, e);
536 var t = e.getTarget();
538 var cell = Roo.get(t);
544 if(cell.findParent('tfoot', false, true)){
548 if(cell.findParent('thead', false, true)){
550 if(e.getTarget().nodeName.toLowerCase() != 'th'){
551 cell = Roo.get(t).findParent('th', false, true);
553 Roo.log("failed to find th in thead?");
554 Roo.log(e.getTarget());
559 var cellIndex = cell.dom.cellIndex;
561 var ename = name == 'touchstart' ? 'click' : name;
562 this.fireEvent("header" + ename, this, cellIndex, e);
567 if(e.getTarget().nodeName.toLowerCase() != 'td'){
568 cell = Roo.get(t).findParent('td', false, true);
570 Roo.log("failed to find th in tbody?");
571 Roo.log(e.getTarget());
576 var row = cell.findParent('tr', false, true);
577 var cellIndex = cell.dom.cellIndex;
578 var rowIndex = row.dom.rowIndex - 1;
582 this.fireEvent("row" + name, this, rowIndex, e);
586 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
592 onMouseover : function(e, el)
594 var cell = Roo.get(el);
600 if(e.getTarget().nodeName.toLowerCase() != 'td'){
601 cell = cell.findParent('td', false, true);
604 var row = cell.findParent('tr', false, true);
605 var cellIndex = cell.dom.cellIndex;
606 var rowIndex = row.dom.rowIndex - 1; // start from 0
608 this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
612 onMouseout : function(e, el)
614 var cell = Roo.get(el);
620 if(e.getTarget().nodeName.toLowerCase() != 'td'){
621 cell = cell.findParent('td', false, true);
624 var row = cell.findParent('tr', false, true);
625 var cellIndex = cell.dom.cellIndex;
626 var rowIndex = row.dom.rowIndex - 1; // start from 0
628 this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
632 onClick : function(e, el)
634 var cell = Roo.get(el);
636 if(!cell || (!this.cellSelection && !this.rowSelection)){
640 if(e.getTarget().nodeName.toLowerCase() != 'td'){
641 cell = cell.findParent('td', false, true);
644 if(!cell || typeof(cell) == 'undefined'){
648 var row = cell.findParent('tr', false, true);
650 if(!row || typeof(row) == 'undefined'){
654 var cellIndex = cell.dom.cellIndex;
655 var rowIndex = this.getRowIndex(row);
657 // why??? - should these not be based on SelectionModel?
658 //if(this.cellSelection){
659 this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
662 //if(this.rowSelection){
663 this.fireEvent('rowclick', this, row, rowIndex, e);
668 onDblClick : function(e,el)
670 var cell = Roo.get(el);
672 if(!cell || (!this.cellSelection && !this.rowSelection)){
676 if(e.getTarget().nodeName.toLowerCase() != 'td'){
677 cell = cell.findParent('td', false, true);
680 if(!cell || typeof(cell) == 'undefined'){
684 var row = cell.findParent('tr', false, true);
686 if(!row || typeof(row) == 'undefined'){
690 var cellIndex = cell.dom.cellIndex;
691 var rowIndex = this.getRowIndex(row);
693 if(this.cellSelection){
694 this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
697 if(this.rowSelection){
698 this.fireEvent('rowdblclick', this, row, rowIndex, e);
701 findRowIndex : function(el)
703 var cell = Roo.get(el);
707 var row = cell.findParent('tr', false, true);
709 if(!row || typeof(row) == 'undefined'){
712 return this.getRowIndex(row);
714 sort : function(e,el)
716 var col = Roo.get(el);
718 if(!col.hasClass('sortable')){
722 var sort = col.attr('sort');
725 if(col.select('i', true).first().hasClass('fa-arrow-up')){
729 this.store.sortInfo = {field : sort, direction : dir};
732 Roo.log("calling footer first");
733 this.footer.onClick('first');
736 this.store.load({ params : { start : 0 } });
740 renderHeader : function()
750 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
752 var config = cm.config[i];
759 html: cm.getColumnHeader(i)
762 var tooltip = cm.getColumnTooltip(i);
770 if(typeof(config.sortable) != 'undefined' && config.sortable){
771 c.cls += ' sortable';
772 c.html = '<i class="fa"></i>' + c.html;
775 // could use BS4 hidden-..-down
777 if(typeof(config.lgHeader) != 'undefined'){
778 hh += '<span class="hidden-xs hidden-sm hidden-md ">' + config.lgHeader + '</span>';
781 if(typeof(config.mdHeader) != 'undefined'){
782 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
785 if(typeof(config.smHeader) != 'undefined'){
786 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
789 if(typeof(config.xsHeader) != 'undefined'){
790 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
797 if(typeof(config.tooltip) != 'undefined'){
798 c.tooltip = config.tooltip;
801 if(typeof(config.colspan) != 'undefined'){
802 c.colspan = config.colspan;
805 // hidden is handled by CSS now
807 if(typeof(config.dataIndex) != 'undefined'){
808 c.sort = config.dataIndex;
813 if(typeof(config.align) != 'undefined' && config.align.length){
814 c.style += ' text-align:' + config.align + ';';
817 /* width is done in CSS
818 *if(typeof(config.width) != 'undefined'){
819 c.style += ' width:' + config.width + 'px;';
820 this.totalWidth += config.width;
822 this.totalWidth += 100; // assume minimum of 100 per column?
826 if(typeof(config.cls) != 'undefined'){
827 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
829 // this is the bit that doesnt reall work at all...
831 if (this.responsive) {
834 ['xs','sm','md','lg'].map(function(size){
836 if(typeof(config[size]) == 'undefined'){
840 if (!config[size]) { // 0 = hidden
841 // BS 4 '0' is treated as hide that column and below.
842 c.cls += ' hidden-' + size + ' hidden' + size + '-down';
846 c.cls += ' col-' + size + '-' + config[size] + (
847 size == 'xs' ? (' col-' + config[size] ) : '' // bs4 col-{num} replaces col-xs
855 c.html +=' <span class="x-grid-split x-grid-split-' + i + '"></span>';
866 renderBody : function()
876 colspan : this.cm.getColumnCount()
886 renderFooter : function()
896 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 Roo.each(this.el.select('tbody td', true).elements, function(e){
966 e.on('mouseover', _this.onMouseover, _this);
969 Roo.each(this.el.select('tbody td', true).elements, function(e){
970 e.on('mouseout', _this.onMouseout, _this);
972 this.fireEvent('rowsrendered', this);
976 this.initCSS(); /// resize cols
982 onUpdate : function(ds,record)
984 this.refreshRow(record);
988 onRemove : function(ds, record, index, isUpdate){
989 if(isUpdate !== true){
990 this.fireEvent("beforerowremoved", this, index, record);
992 var bt = this.bodyEl.dom;
994 var rows = this.el.select('tbody > tr', true).elements;
996 if(typeof(rows[index]) != 'undefined'){
997 bt.removeChild(rows[index].dom);
1000 // if(bt.rows[index]){
1001 // bt.removeChild(bt.rows[index]);
1004 if(isUpdate !== true){
1005 //this.stripeRows(index);
1006 //this.syncRowHeights(index, index);
1008 this.fireEvent("rowremoved", this, index, record);
1012 onAdd : function(ds, records, rowIndex)
1014 //Roo.log('on Add called');
1015 // - note this does not handle multiple adding very well..
1016 var bt = this.bodyEl.dom;
1017 for (var i =0 ; i < records.length;i++) {
1018 //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
1019 //Roo.log(records[i]);
1020 //Roo.log(this.store.getAt(rowIndex+i));
1021 this.insertRow(this.store, rowIndex + i, false);
1028 refreshRow : function(record){
1029 var ds = this.store, index;
1030 if(typeof record == 'number'){
1032 record = ds.getAt(index);
1034 index = ds.indexOf(record);
1036 return; // should not happen - but seems to
1039 this.insertRow(ds, index, true);
1041 this.onRemove(ds, record, index+1, true);
1043 //this.syncRowHeights(index, index);
1045 this.fireEvent("rowupdated", this, index, record);
1047 // private - called by RowSelection
1048 onRowSelect : function(rowIndex){
1049 var row = this.getRowDom(rowIndex);
1050 row.addClass(['bg-info','info']);
1052 // private - called by RowSelection
1053 onRowDeselect : function(rowIndex)
1058 var row = this.getRowDom(rowIndex);
1059 row.removeClass(['bg-info','info']);
1062 * Focuses the specified row.
1063 * @param {Number} row The row index
1065 focusRow : function(row)
1067 //Roo.log('GridView.focusRow');
1068 var x = this.bodyEl.dom.scrollLeft;
1069 this.focusCell(row, 0, false);
1070 this.bodyEl.dom.scrollLeft = x;
1074 * Focuses the specified cell.
1075 * @param {Number} row The row index
1076 * @param {Number} col The column index
1077 * @param {Boolean} hscroll false to disable horizontal scrolling
1079 focusCell : function(row, col, hscroll)
1081 //Roo.log('GridView.focusCell');
1082 var el = this.ensureVisible(row, col, hscroll);
1083 // not sure what focusEL achives = it's a <a> pos relative
1084 //this.focusEl.alignTo(el, "tl-tl");
1086 // this.focusEl.focus();
1088 // this.focusEl.focus.defer(1, this.focusEl);
1093 * Scrolls the specified cell into view
1094 * @param {Number} row The row index
1095 * @param {Number} col The column index
1096 * @param {Boolean} hscroll false to disable horizontal scrolling
1098 ensureVisible : function(row, col, hscroll)
1100 //Roo.log('GridView.ensureVisible,' + row + ',' + col);
1101 //return null; //disable for testing.
1102 if(typeof row != "number"){
1105 if(row < 0 && row >= this.ds.getCount()){
1108 col = (col !== undefined ? col : 0);
1110 while(cm.isHidden(col)){
1114 var el = this.getCellDom(row, col);
1118 var c = this.bodyEl.dom;
1120 var ctop = parseInt(el.offsetTop, 10);
1121 var cleft = parseInt(el.offsetLeft, 10);
1122 var cbot = ctop + el.offsetHeight;
1123 var cright = cleft + el.offsetWidth;
1125 //var ch = c.clientHeight - this.mainHd.dom.offsetHeight;
1126 var ch = 0; //?? header is not withing the area?
1127 var stop = parseInt(c.scrollTop, 10);
1128 var sleft = parseInt(c.scrollLeft, 10);
1129 var sbot = stop + ch;
1130 var sright = sleft + c.clientWidth;
1132 Roo.log('GridView.ensureVisible:' +
1134 ' c.clientHeight:' + c.clientHeight +
1135 ' this.mainHd.dom.offsetHeight:' + this.mainHd.dom.offsetHeight +
1144 //Roo.log("set scrolltop to ctop DISABLE?");
1145 }else if(cbot > sbot){
1146 //Roo.log("set scrolltop to cbot-ch");
1147 c.scrollTop = cbot-ch;
1150 if(hscroll !== false){
1152 c.scrollLeft = cleft;
1153 }else if(cright > sright){
1154 c.scrollLeft = cright-c.clientWidth;
1162 insertRow : function(dm, rowIndex, isUpdate){
1165 this.fireEvent("beforerowsinserted", this, rowIndex);
1167 //var s = this.getScrollState();
1168 var row = this.renderRow(this.cm, this.store, rowIndex);
1169 // insert before rowIndex..
1170 var e = this.bodyEl.createChild(row,this.getRowDom(rowIndex));
1174 if(row.cellObjects.length){
1175 Roo.each(row.cellObjects, function(r){
1176 _this.renderCellObject(r);
1181 this.fireEvent("rowsinserted", this, rowIndex);
1182 //this.syncRowHeights(firstRow, lastRow);
1183 //this.stripeRows(firstRow);
1190 getRowDom : function(rowIndex)
1192 var rows = this.el.select('tbody > tr', true).elements;
1194 return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
1197 getCellDom : function(rowIndex, colIndex)
1199 var row = this.getRowDom(rowIndex);
1200 if (row === false) {
1203 var cols = row.select('td', true).elements;
1204 return (typeof(cols[colIndex]) == 'undefined') ? false : cols[colIndex];
1208 // returns the object tree for a tr..
1211 renderRow : function(cm, ds, rowIndex)
1213 var d = ds.getAt(rowIndex);
1217 cls : 'x-row-' + rowIndex,
1221 var cellObjects = [];
1223 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
1224 var config = cm.config[i];
1226 var renderer = cm.getRenderer(i);
1230 if(typeof(renderer) !== 'undefined'){
1231 value = renderer(d.data[cm.getDataIndex(i)], false, d);
1233 // if object are returned, then they are expected to be Roo.bootstrap.Component instances
1234 // and are rendered into the cells after the row is rendered - using the id for the element.
1236 if(typeof(value) === 'object'){
1246 rowIndex : rowIndex,
1251 this.fireEvent('rowclass', this, rowcfg);
1255 // this might end up displaying HTML?
1256 // this is too messy... - better to only do it on columsn you know are going to be too long
1257 //tooltip : (typeof(value) === 'object') ? '' : value,
1258 cls : rowcfg.rowClass + ' x-col-' + i,
1260 html: (typeof(value) === 'object') ? '' : value
1267 if(typeof(config.colspan) != 'undefined'){
1268 td.colspan = config.colspan;
1273 if(typeof(config.align) != 'undefined' && config.align.length){
1274 td.style += ' text-align:' + config.align + ';';
1276 if(typeof(config.valign) != 'undefined' && config.valign.length){
1277 td.style += ' vertical-align:' + config.valign + ';';
1280 if(typeof(config.width) != 'undefined'){
1281 td.style += ' width:' + config.width + 'px;';
1285 if(typeof(config.cursor) != 'undefined'){
1286 td.style += ' cursor:' + config.cursor + ';';
1289 if(typeof(config.cls) != 'undefined'){
1290 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
1292 if (this.responsive) {
1293 ['xs','sm','md','lg'].map(function(size){
1295 if(typeof(config[size]) == 'undefined'){
1301 if (!config[size]) { // 0 = hidden
1302 // BS 4 '0' is treated as hide that column and below.
1303 td.cls += ' hidden-' + size + ' hidden' + size + '-down';
1307 td.cls += ' col-' + size + '-' + config[size] + (
1308 size == 'xs' ? (' col-' + config[size] ) : '' // bs4 col-{num} replaces col-xs
1318 row.cellObjects = cellObjects;
1326 onBeforeLoad : function()
1328 this.el.unmask(); // if needed.
1335 this.el.select('tbody', true).first().dom.innerHTML = '';
1338 * Show or hide a row.
1339 * @param {Number} rowIndex to show or hide
1340 * @param {Boolean} state hide
1342 setRowVisibility : function(rowIndex, state)
1344 var bt = this.bodyEl.dom;
1346 var rows = this.el.select('tbody > tr', true).elements;
1348 if(typeof(rows[rowIndex]) == 'undefined'){
1351 rows[rowIndex][ state ? 'removeClass' : 'addClass']('d-none');
1356 getSelectionModel : function(){
1358 this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
1360 return this.selModel;
1363 * Render the Roo.bootstrap object from renderder
1365 renderCellObject : function(r)
1369 r.cfg.parentId = (typeof(r.container) == 'string') ? r.container : r.container.id;
1371 var t = r.cfg.render(r.container);
1374 Roo.each(r.cfg.cn, function(c){
1376 container: t.getChildContainer(),
1379 _this.renderCellObject(child);
1384 * get the Row Index from a dom element.
1385 * @param {Roo.Element} row The row to look for
1386 * @returns {Number} the row
1388 getRowIndex : function(row)
1392 Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
1403 * get the header TH element for columnIndex
1404 * @param {Number} columnIndex
1405 * @returns {Roo.Element}
1407 getHeaderIndex: function(colIndex)
1409 var cols = this.headEl.select('th', true).elements;
1410 return cols[colIndex];
1413 * get the Column Index from a dom element. (using regex on x-hcol-{colid})
1414 * @param {domElement} cell to look for
1415 * @returns {Number} the column
1417 getCellIndex : function(cell)
1419 var id = String(cell.className).match(Roo.bootstrap.Table.cellRE);
1421 return parseInt(id[1], 10);
1426 * Returns the grid's underlying element = used by panel.Grid
1427 * @return {Element} The element
1429 getGridEl : function(){
1433 * Forces a resize - used by panel.Grid
1434 * @return {Element} The element
1436 autoSize : function()
1438 if(this.disableAutoSize) {
1439 Roo.log("DISABLEAUTOSIZE");
1442 //var ctr = Roo.get(this.container.dom.parentElement);
1443 var ctr = Roo.get(this.el.dom);
1445 var thd = this.getGridEl().select('thead',true).first();
1446 var tbd = this.getGridEl().select('tbody', true).first();
1447 var tfd = this.getGridEl().select('tfoot', true).first();
1449 var cw = ctr.getWidth();
1450 this.getGridEl().select('tfoot tr, tfoot td',true).setWidth(cw);
1454 tbd.setWidth(ctr.getWidth());
1455 // if the body has a max height - and then scrolls - we should perhaps set up the height here
1456 // this needs fixing for various usage - currently only hydra job advers I think..
1458 // ctr.getHeight() - ((thd ? thd.getHeight() : 0) + (tfd ? tfd.getHeight() : 0))
1460 var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
1463 cw = Math.max(cw, this.totalWidth);
1464 this.getGridEl().select('tbody tr',true).setWidth(cw);
1467 // resize 'expandable coloumn?
1469 return; // we doe not have a view in this design..
1472 onBodyScroll: function()
1474 //Roo.log("body scrolled');" + this.bodyEl.dom.scrollLeft);
1476 this.headEl.setStyle({
1477 'position' : 'relative',
1478 'left': (-1* this.bodyEl.dom.scrollLeft) + 'px'
1484 var scrollHeight = this.bodyEl.dom.scrollHeight;
1486 var scrollTop = Math.ceil(this.bodyEl.getScroll().top);
1488 var height = this.bodyEl.getHeight();
1490 if(scrollHeight - height == scrollTop) {
1492 var total = this.ds.getTotalCount();
1494 if(this.footer.cursor + this.footer.pageSize < total){
1496 this.footer.ds.load({
1498 start : this.footer.cursor + this.footer.pageSize,
1499 limit : this.footer.pageSize
1508 onColumnSplitterMoved : function(i, diff)
1510 this.userResized = true;
1512 var cm = this.colModel;
1514 var w = this.getHeaderIndex(i).getWidth() + diff;
1517 cm.setColumnWidth(i, w, true);
1519 //var cid = cm.getColumnId(i); << not used in this version?
1520 /* Roo.log(['#' + this.id + ' .x-col-' + i, "width", w + "px"]);
1522 this.CSS.updateRule( '#' + this.id + ' .x-col-' + i, "width", w + "px");
1523 this.CSS.updateRule('#' + this.id + ' .x-hcol-' + i, "width", w + "px");
1524 this.CSS.updateRule('#' + this.id + ' .x-grid-split-' + i, "left", w + "px");
1526 //this.updateSplitters();
1527 //this.layout(); << ??
1528 this.fireEvent("columnresize", i, w);
1530 onHeaderChange : function()
1532 var header = this.renderHeader();
1533 var table = this.el.select('table', true).first();
1535 this.headEl.remove();
1536 this.headEl = table.createChild(header, this.bodyEl, false);
1538 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
1539 e.on('click', this.sort, this);
1542 if(this.enableColumnResize !== false && Roo.grid.SplitDragZone){
1543 new Roo.grid.SplitDragZone(this, this.headEl.dom, false); // not sure what 'lockedHd is for this implementation..)
1548 onHiddenChange : function(colModel, colIndex, hidden)
1552 var thSelector = '#' + this.id + ' .x-hcol-' + colIndex;
1553 var tdSelector = '#' + this.id + ' .x-col-' + colIndex;
1555 this.CSS.updateRule(thSelector, "display", "");
1556 this.CSS.updateRule(tdSelector, "display", "");
1559 this.CSS.updateRule(thSelector, "display", "none");
1560 this.CSS.updateRule(tdSelector, "display", "none");
1563 // onload calls initCSS()
1564 this.onHeaderChange();
1568 setColumnWidth: function(col_index, width)
1570 // width = "md-2 xs-2..."
1571 if(!this.colModel.config[col_index]) {
1575 var w = width.split(" ");
1577 var rows = this.el.dom.getElementsByClassName("x-col-"+col_index);
1579 var h_row = this.el.dom.getElementsByClassName("x-hcol-"+col_index);
1582 for(var j = 0; j < w.length; j++) {
1588 var size_cls = w[j].split("-");
1590 if(!Number.isInteger(size_cls[1] * 1)) {
1594 if(!this.colModel.config[col_index][size_cls[0]]) {
1598 if(!h_row[0].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
1602 h_row[0].classList.replace(
1603 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
1604 "col-"+size_cls[0]+"-"+size_cls[1]
1607 for(var i = 0; i < rows.length; i++) {
1609 var size_cls = w[j].split("-");
1611 if(!Number.isInteger(size_cls[1] * 1)) {
1615 if(!this.colModel.config[col_index][size_cls[0]]) {
1619 if(!rows[i].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
1623 rows[i].classList.replace(
1624 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
1625 "col-"+size_cls[0]+"-"+size_cls[1]
1629 this.colModel.config[col_index][size_cls[0]] = size_cls[1];
1634 // currently only used to find the split on drag..
1635 Roo.bootstrap.Table.cellRE = /(?:.*?)x-grid-(?:hd|cell|split)-([\d]+)(?:.*?)/;
1640 Roo.bootstrap.Table.AbstractSelectionModel = Roo.grid.AbstractSelectionModel;
1641 Roo.bootstrap.Table.RowSelectionModel = Roo.grid.RowSelectionModel;