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)
93 * @cfg {Number} minColumnWidth default 50 pixels minimum column width
97 * @param {Object} config The config object
100 Roo.bootstrap.Table = function(config)
102 Roo.bootstrap.Table.superclass.constructor.call(this, config);
105 this.rowSelection = (typeof(config.rowSelection) != 'undefined') ? config.rowSelection : this.rowSelection;
106 this.cellSelection = (typeof(config.cellSelection) != 'undefined') ? config.cellSelection : this.cellSelection;
107 this.headerShow = (typeof(config.thead) != 'undefined') ? config.thead : this.headerShow;
108 this.footerShow = (typeof(config.tfoot) != 'undefined') ? config.tfoot : this.footerShow;
110 this.view = this; // compat with grid.
112 this.sm = this.sm || {xtype: 'RowSelectionModel'};
115 this.selModel = Roo.factory(this.sm, Roo.grid);
116 this.sm = this.selModel;
117 this.sm.xmodule = this.xmodule || false;
120 if (this.cm && typeof(this.cm.config) == 'undefined') {
121 this.colModel = new Roo.grid.ColumnModel(this.cm);
122 this.cm = this.colModel;
123 this.cm.xmodule = this.xmodule || false;
126 this.store= Roo.factory(this.store, Roo.data);
127 this.ds = this.store;
128 this.ds.xmodule = this.xmodule || false;
131 if (this.footer && this.store) {
132 this.footer.dataSource = this.ds;
133 this.footer = Roo.factory(this.footer);
140 * Fires when a cell is clicked
141 * @param {Roo.bootstrap.Table} this
142 * @param {Roo.Element} el
143 * @param {Number} rowIndex
144 * @param {Number} columnIndex
145 * @param {Roo.EventObject} e
149 * @event celldblclick
150 * Fires when a cell is double clicked
151 * @param {Roo.bootstrap.Table} this
152 * @param {Roo.Element} el
153 * @param {Number} rowIndex
154 * @param {Number} columnIndex
155 * @param {Roo.EventObject} e
157 "celldblclick" : true,
160 * Fires when a row is clicked
161 * @param {Roo.bootstrap.Table} this
162 * @param {Roo.Element} el
163 * @param {Number} rowIndex
164 * @param {Roo.EventObject} e
169 * Fires when a row is double clicked
170 * @param {Roo.bootstrap.Table} this
171 * @param {Roo.Element} el
172 * @param {Number} rowIndex
173 * @param {Roo.EventObject} e
175 "rowdblclick" : true,
178 * Fires when a mouseover occur
179 * @param {Roo.bootstrap.Table} this
180 * @param {Roo.Element} el
181 * @param {Number} rowIndex
182 * @param {Number} columnIndex
183 * @param {Roo.EventObject} e
188 * Fires when a mouseout occur
189 * @param {Roo.bootstrap.Table} this
190 * @param {Roo.Element} el
191 * @param {Number} rowIndex
192 * @param {Number} columnIndex
193 * @param {Roo.EventObject} e
198 * Fires when a row is rendered, so you can change add a style to it.
199 * @param {Roo.bootstrap.Table} this
200 * @param {Object} rowcfg contains record rowIndex colIndex and rowClass - set rowClass to add a style.
204 * @event rowsrendered
205 * Fires when all the rows have been rendered
206 * @param {Roo.bootstrap.Table} this
208 'rowsrendered' : true,
211 * The raw contextmenu event for the entire grid.
212 * @param {Roo.EventObject} e
214 "contextmenu" : true,
216 * @event rowcontextmenu
217 * Fires when a row is right clicked
218 * @param {Roo.bootstrap.Table} this
219 * @param {Number} rowIndex
220 * @param {Roo.EventObject} e
222 "rowcontextmenu" : true,
224 * @event cellcontextmenu
225 * Fires when a cell is right clicked
226 * @param {Roo.bootstrap.Table} this
227 * @param {Number} rowIndex
228 * @param {Number} cellIndex
229 * @param {Roo.EventObject} e
231 "cellcontextmenu" : true,
233 * @event headercontextmenu
234 * Fires when a header is right clicked
235 * @param {Roo.bootstrap.Table} this
236 * @param {Number} columnIndex
237 * @param {Roo.EventObject} e
239 "headercontextmenu" : true,
242 * The raw mousedown event for the entire grid.
243 * @param {Roo.EventObject} e
250 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component, {
267 enableColumnResize: true,
269 rowSelection : false,
270 cellSelection : false,
275 // Roo.Element - the tbody
276 bodyEl: false, // <tbody> Roo.Element - thead element
277 headEl: false, // <thead> Roo.Element - thead element
278 resizeProxy : false, // proxy element for dragging?
282 container: false, // used by gridpanel...
288 auto_hide_footer : false,
290 view: false, // actually points to this..
292 getAutoCreate : function()
294 var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
301 // this get's auto added by panel.Grid
302 if (this.scrollBody) {
303 cfg.cls += ' table-body-fixed';
306 cfg.cls += ' table-striped';
310 cfg.cls += ' table-hover';
313 cfg.cls += ' table-bordered';
315 if (this.condensed) {
316 cfg.cls += ' table-condensed';
319 if (this.responsive) {
320 cfg.cls += ' table-responsive';
324 cfg.cls+= ' ' +this.cls;
330 cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
333 if(this.store || this.cm){
335 cfg.cn.push(this.renderHeader());
338 cfg.cn.push(this.renderBody());
341 cfg.cn.push(this.renderFooter());
343 // where does this come from?
344 //cfg.cls+= ' TableGrid';
347 return { cn : [ cfg ] };
350 initEvents : function()
352 if(!this.store || !this.cm){
356 this.selModel.initEvents();
360 //Roo.log('initEvents with ds!!!!');
362 this.bodyEl = this.el.select('tbody', true).first();
363 this.headEl = this.el.select('thead', true).first();
364 this.mainFoot = this.el.select('tfoot', true).first();
369 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
370 e.on('click', this.sort, this);
374 // why is this done????? = it breaks dialogs??
375 //this.parent().el.setStyle('position', 'relative');
379 this.footer.parentId = this.id;
380 this.footer.onRender(this.el.select('tfoot tr td').first(), null);
383 this.el.select('tfoot tr td').first().addClass('hide');
388 this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
391 this.store.on('load', this.onLoad, this);
392 this.store.on('beforeload', this.onBeforeLoad, this);
393 this.store.on('update', this.onUpdate, this);
394 this.store.on('add', this.onAdd, this);
395 this.store.on("clear", this.clear, this);
397 this.el.on("contextmenu", this.onContextMenu, this);
400 this.cm.on("headerchange", this.onHeaderChange, this);
401 this.cm.on("hiddenchange", this.onHiddenChange, this, arguments);
403 //?? does bodyEl get replaced on render?
404 this.bodyEl.on("click", this.onClick, this);
405 this.bodyEl.on("dblclick", this.onDblClick, this);
406 this.bodyEl.on('scroll', this.onBodyScroll, this);
408 // guessing mainbody will work - this relays usually caught by selmodel at present.
409 this.relayEvents(this.bodyEl, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
412 this.resizeProxy = Roo.get(document.body).createChild({ cls:"x-grid-resize-proxy", html: ' ' });
415 if(this.headEl && this.enableColumnResize !== false && Roo.grid.SplitDragZone){
416 new Roo.grid.SplitDragZone(this, this.headEl.dom, false); // not sure what 'lockedHd is for this implementation..)
421 // Compatibility with grid - we implement all the view features at present.
431 var cm = this.cm, styles = [];
432 this.CSS.removeStyleSheet(this.id + '-cssrules');
433 var headHeight = this.headEl ? this.headEl.dom.clientHeight : 0;
434 // we can honour xs/sm/md/xl as widths...
435 // we first have to decide what widht we are currently at...
436 var sz = Roo.getGridSize();
440 var cols = []; // visable cols.
442 for(var i = 0, len = cm.getColumnCount(); i < len; i++) {
443 var w = cm.getColumnWidth(i, false);
445 cols.push( { rel : false, abs : 0 });
449 cols.push( { rel : false, abs : w });
451 last = i; // not really..
454 var w = cm.getColumnWidth(i, sz);
459 cols.push( { rel : w, abs : false });
462 var avail = this.bodyEl.dom.clientWidth - total_abs;
464 var unitWidth = Math.floor(avail / total);
465 var rem = avail - (unitWidth * total);
467 var hidden, width, pos = 0 , splithide , left;
468 for(var i = 0, len = cm.getColumnCount(); i < len; i++) {
470 hidden = 'display:none;';
472 width = 'width:0px;';
478 // we can honour xs/sm/md/xl ?
479 var w = cols[i].rel == false ? cols[i].abs : (cols[i].rel * unitWidth);
481 hidden = 'display:none;';
483 // width should return a small number...
485 w+=rem; // add the remaining with..
488 left = "left:" + (pos -4) + "px;";
489 width = "width:" + w+ "px;";
492 if (this.responsive) {
495 hidden = cm.isHidden(i) ? 'display:none;' : '';
496 splithide = 'display: none;';
499 styles.push( '#' , this.id , ' .x-col-' , i, " {", cm.config[i].css, width, hidden, "}\n" );
502 splithide = 'display:none;';
505 styles.push('#' , this.id , ' .x-hcol-' , i, " { ", width, hidden," }\n",
506 '#' , this.id , ' .x-grid-split-' , i, " { ", left, splithide, 'height:', (headHeight - 4), "px;}\n",
507 // this is the popover version..
508 '.popover-inner #' , this.id , ' .x-grid-split-' , i, " { ", left, splithide, 'height:', 100, "%;}\n"
513 //Roo.log(styles.join(''));
514 this.CSS.createStyleSheet( styles.join(''), this.id + '-cssrules');
520 onContextMenu : function(e, t)
522 this.processEvent("contextmenu", e);
525 processEvent : function(name, e)
527 if (name != 'touchstart' ) {
528 this.fireEvent(name, e);
531 var t = e.getTarget();
533 var cell = Roo.get(t);
539 if(cell.findParent('tfoot', false, true)){
543 if(cell.findParent('thead', false, true)){
545 if(e.getTarget().nodeName.toLowerCase() != 'th'){
546 cell = Roo.get(t).findParent('th', false, true);
548 Roo.log("failed to find th in thead?");
549 Roo.log(e.getTarget());
554 var cellIndex = cell.dom.cellIndex;
556 var ename = name == 'touchstart' ? 'click' : name;
557 this.fireEvent("header" + ename, this, cellIndex, e);
562 if(e.getTarget().nodeName.toLowerCase() != 'td'){
563 cell = Roo.get(t).findParent('td', false, true);
565 Roo.log("failed to find th in tbody?");
566 Roo.log(e.getTarget());
571 var row = cell.findParent('tr', false, true);
572 var cellIndex = cell.dom.cellIndex;
573 var rowIndex = row.dom.rowIndex - 1;
577 this.fireEvent("row" + name, this, rowIndex, e);
581 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
587 onMouseover : function(e, el)
589 var cell = Roo.get(el);
595 if(e.getTarget().nodeName.toLowerCase() != 'td'){
596 cell = cell.findParent('td', false, true);
599 var row = cell.findParent('tr', false, true);
600 var cellIndex = cell.dom.cellIndex;
601 var rowIndex = row.dom.rowIndex - 1; // start from 0
603 this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
607 onMouseout : function(e, el)
609 var cell = Roo.get(el);
615 if(e.getTarget().nodeName.toLowerCase() != 'td'){
616 cell = cell.findParent('td', false, true);
619 var row = cell.findParent('tr', false, true);
620 var cellIndex = cell.dom.cellIndex;
621 var rowIndex = row.dom.rowIndex - 1; // start from 0
623 this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
627 onClick : function(e, el)
629 var cell = Roo.get(el);
631 if(!cell || (!this.cellSelection && !this.rowSelection)){
635 if(e.getTarget().nodeName.toLowerCase() != 'td'){
636 cell = cell.findParent('td', false, true);
639 if(!cell || typeof(cell) == 'undefined'){
643 var row = cell.findParent('tr', false, true);
645 if(!row || typeof(row) == 'undefined'){
649 var cellIndex = cell.dom.cellIndex;
650 var rowIndex = this.getRowIndex(row);
652 // why??? - should these not be based on SelectionModel?
653 //if(this.cellSelection){
654 this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
657 //if(this.rowSelection){
658 this.fireEvent('rowclick', this, row, rowIndex, e);
663 onDblClick : function(e,el)
665 var cell = Roo.get(el);
667 if(!cell || (!this.cellSelection && !this.rowSelection)){
671 if(e.getTarget().nodeName.toLowerCase() != 'td'){
672 cell = cell.findParent('td', false, true);
675 if(!cell || typeof(cell) == 'undefined'){
679 var row = cell.findParent('tr', false, true);
681 if(!row || typeof(row) == 'undefined'){
685 var cellIndex = cell.dom.cellIndex;
686 var rowIndex = this.getRowIndex(row);
688 if(this.cellSelection){
689 this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
692 if(this.rowSelection){
693 this.fireEvent('rowdblclick', this, row, rowIndex, e);
696 findRowIndex : function(el)
698 var cell = Roo.get(el);
702 var row = cell.findParent('tr', false, true);
704 if(!row || typeof(row) == 'undefined'){
707 return this.getRowIndex(row);
709 sort : function(e,el)
711 var col = Roo.get(el);
713 if(!col.hasClass('sortable')){
717 var sort = col.attr('sort');
720 if(col.select('i', true).first().hasClass('fa-arrow-up')){
724 this.store.sortInfo = {field : sort, direction : dir};
727 Roo.log("calling footer first");
728 this.footer.onClick('first');
731 this.store.load({ params : { start : 0 } });
735 renderHeader : function()
745 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
747 var config = cm.config[i];
754 html: cm.getColumnHeader(i)
757 var tooltip = cm.getColumnTooltip(i);
765 if(typeof(config.sortable) != 'undefined' && config.sortable){
766 c.cls += ' sortable';
767 c.html = '<i class="fa"></i>' + c.html;
770 // could use BS4 hidden-..-down
772 if(typeof(config.lgHeader) != 'undefined'){
773 hh += '<span class="hidden-xs hidden-sm hidden-md ">' + config.lgHeader + '</span>';
776 if(typeof(config.mdHeader) != 'undefined'){
777 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
780 if(typeof(config.smHeader) != 'undefined'){
781 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
784 if(typeof(config.xsHeader) != 'undefined'){
785 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
792 if(typeof(config.tooltip) != 'undefined'){
793 c.tooltip = config.tooltip;
796 if(typeof(config.colspan) != 'undefined'){
797 c.colspan = config.colspan;
800 // hidden is handled by CSS now
802 if(typeof(config.dataIndex) != 'undefined'){
803 c.sort = config.dataIndex;
808 if(typeof(config.align) != 'undefined' && config.align.length){
809 c.style += ' text-align:' + config.align + ';';
812 /* width is done in CSS
813 *if(typeof(config.width) != 'undefined'){
814 c.style += ' width:' + config.width + 'px;';
815 this.totalWidth += config.width;
817 this.totalWidth += 100; // assume minimum of 100 per column?
821 if(typeof(config.cls) != 'undefined'){
822 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
824 // this is the bit that doesnt reall work at all...
826 if (this.responsive) {
829 ['xs','sm','md','lg'].map(function(size){
831 if(typeof(config[size]) == 'undefined'){
835 if (!config[size]) { // 0 = hidden
836 // BS 4 '0' is treated as hide that column and below.
837 c.cls += ' hidden-' + size + ' hidden' + size + '-down';
841 c.cls += ' col-' + size + '-' + config[size] + (
842 size == 'xs' ? (' col-' + config[size] ) : '' // bs4 col-{num} replaces col-xs
850 c.html +=' <span class="x-grid-split x-grid-split-' + i + '"></span>';
861 renderBody : function()
871 colspan : this.cm.getColumnCount()
881 renderFooter : function()
891 colspan : this.cm.getColumnCount()
905 // Roo.log('ds onload');
912 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
913 e.select('i', true).removeClass(['fa-arrow-up', 'fa-arrow-down']);
914 if (_this.store.sortInfo) {
916 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
917 e.select('i', true).addClass(['fa-arrow-up']);
920 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
921 e.select('i', true).addClass(['fa-arrow-down']);
926 var tbody = this.bodyEl;
928 if(ds.getCount() > 0){
929 ds.data.each(function(d,rowIndex){
930 var row = this.renderRow(cm, ds, rowIndex);
932 tbody.createChild(row);
936 if(row.cellObjects.length){
937 Roo.each(row.cellObjects, function(r){
938 _this.renderCellObject(r);
943 } else if (this.empty_results.length) {
944 this.el.mask(this.empty_results, 'no-spinner');
947 var tfoot = this.el.select('tfoot', true).first();
949 if(this.footerShow && this.auto_hide_footer && this.mainFoot){
951 this.mainFoot.setVisibilityMode(Roo.Element.DISPLAY).hide();
953 var total = this.ds.getTotalCount();
955 if(this.footer.pageSize < total){
956 this.mainFoot.show();
960 Roo.each(this.el.select('tbody td', true).elements, function(e){
961 e.on('mouseover', _this.onMouseover, _this);
964 Roo.each(this.el.select('tbody td', true).elements, function(e){
965 e.on('mouseout', _this.onMouseout, _this);
967 this.fireEvent('rowsrendered', this);
971 this.initCSS(); /// resize cols
977 onUpdate : function(ds,record)
979 this.refreshRow(record);
983 onRemove : function(ds, record, index, isUpdate){
984 if(isUpdate !== true){
985 this.fireEvent("beforerowremoved", this, index, record);
987 var bt = this.bodyEl.dom;
989 var rows = this.el.select('tbody > tr', true).elements;
991 if(typeof(rows[index]) != 'undefined'){
992 bt.removeChild(rows[index].dom);
995 // if(bt.rows[index]){
996 // bt.removeChild(bt.rows[index]);
999 if(isUpdate !== true){
1000 //this.stripeRows(index);
1001 //this.syncRowHeights(index, index);
1003 this.fireEvent("rowremoved", this, index, record);
1007 onAdd : function(ds, records, rowIndex)
1009 //Roo.log('on Add called');
1010 // - note this does not handle multiple adding very well..
1011 var bt = this.bodyEl.dom;
1012 for (var i =0 ; i < records.length;i++) {
1013 //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
1014 //Roo.log(records[i]);
1015 //Roo.log(this.store.getAt(rowIndex+i));
1016 this.insertRow(this.store, rowIndex + i, false);
1023 refreshRow : function(record){
1024 var ds = this.store, index;
1025 if(typeof record == 'number'){
1027 record = ds.getAt(index);
1029 index = ds.indexOf(record);
1031 return; // should not happen - but seems to
1034 this.insertRow(ds, index, true);
1036 this.onRemove(ds, record, index+1, true);
1038 //this.syncRowHeights(index, index);
1040 this.fireEvent("rowupdated", this, index, record);
1042 // private - called by RowSelection
1043 onRowSelect : function(rowIndex){
1044 var row = this.getRowDom(rowIndex);
1045 row.addClass(['bg-info','info']);
1047 // private - called by RowSelection
1048 onRowDeselect : function(rowIndex)
1053 var row = this.getRowDom(rowIndex);
1054 row.removeClass(['bg-info','info']);
1057 * Focuses the specified row.
1058 * @param {Number} row The row index
1060 focusRow : function(row)
1062 //Roo.log('GridView.focusRow');
1063 var x = this.bodyEl.dom.scrollLeft;
1064 this.focusCell(row, 0, false);
1065 this.bodyEl.dom.scrollLeft = x;
1069 * Focuses the specified cell.
1070 * @param {Number} row The row index
1071 * @param {Number} col The column index
1072 * @param {Boolean} hscroll false to disable horizontal scrolling
1074 focusCell : function(row, col, hscroll)
1076 //Roo.log('GridView.focusCell');
1077 var el = this.ensureVisible(row, col, hscroll);
1078 // not sure what focusEL achives = it's a <a> pos relative
1079 //this.focusEl.alignTo(el, "tl-tl");
1081 // this.focusEl.focus();
1083 // this.focusEl.focus.defer(1, this.focusEl);
1088 * Scrolls the specified cell into view
1089 * @param {Number} row The row index
1090 * @param {Number} col The column index
1091 * @param {Boolean} hscroll false to disable horizontal scrolling
1093 ensureVisible : function(row, col, hscroll)
1095 //Roo.log('GridView.ensureVisible,' + row + ',' + col);
1096 //return null; //disable for testing.
1097 if(typeof row != "number"){
1100 if(row < 0 && row >= this.ds.getCount()){
1103 col = (col !== undefined ? col : 0);
1105 while(cm.isHidden(col)){
1109 var el = this.getCellDom(row, col);
1113 var c = this.bodyEl.dom;
1115 var ctop = parseInt(el.offsetTop, 10);
1116 var cleft = parseInt(el.offsetLeft, 10);
1117 var cbot = ctop + el.offsetHeight;
1118 var cright = cleft + el.offsetWidth;
1120 //var ch = c.clientHeight - this.mainHd.dom.offsetHeight;
1121 var ch = 0; //?? header is not withing the area?
1122 var stop = parseInt(c.scrollTop, 10);
1123 var sleft = parseInt(c.scrollLeft, 10);
1124 var sbot = stop + ch;
1125 var sright = sleft + c.clientWidth;
1127 Roo.log('GridView.ensureVisible:' +
1129 ' c.clientHeight:' + c.clientHeight +
1130 ' this.mainHd.dom.offsetHeight:' + this.mainHd.dom.offsetHeight +
1139 //Roo.log("set scrolltop to ctop DISABLE?");
1140 }else if(cbot > sbot){
1141 //Roo.log("set scrolltop to cbot-ch");
1142 c.scrollTop = cbot-ch;
1145 if(hscroll !== false){
1147 c.scrollLeft = cleft;
1148 }else if(cright > sright){
1149 c.scrollLeft = cright-c.clientWidth;
1157 insertRow : function(dm, rowIndex, isUpdate){
1160 this.fireEvent("beforerowsinserted", this, rowIndex);
1162 //var s = this.getScrollState();
1163 var row = this.renderRow(this.cm, this.store, rowIndex);
1164 // insert before rowIndex..
1165 var e = this.bodyEl.createChild(row,this.getRowDom(rowIndex));
1169 if(row.cellObjects.length){
1170 Roo.each(row.cellObjects, function(r){
1171 _this.renderCellObject(r);
1176 this.fireEvent("rowsinserted", this, rowIndex);
1177 //this.syncRowHeights(firstRow, lastRow);
1178 //this.stripeRows(firstRow);
1185 getRowDom : function(rowIndex)
1187 var rows = this.el.select('tbody > tr', true).elements;
1189 return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
1192 getCellDom : function(rowIndex, colIndex)
1194 var row = this.getRowDom(rowIndex);
1195 if (row === false) {
1198 var cols = row.select('td', true).elements;
1199 return (typeof(cols[colIndex]) == 'undefined') ? false : cols[colIndex];
1203 // returns the object tree for a tr..
1206 renderRow : function(cm, ds, rowIndex)
1208 var d = ds.getAt(rowIndex);
1212 cls : 'x-row-' + rowIndex,
1216 var cellObjects = [];
1218 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
1219 var config = cm.config[i];
1221 var renderer = cm.getRenderer(i);
1225 if(typeof(renderer) !== 'undefined'){
1226 value = renderer(d.data[cm.getDataIndex(i)], false, d);
1228 // if object are returned, then they are expected to be Roo.bootstrap.Component instances
1229 // and are rendered into the cells after the row is rendered - using the id for the element.
1231 if(typeof(value) === 'object'){
1241 rowIndex : rowIndex,
1246 this.fireEvent('rowclass', this, rowcfg);
1250 // this might end up displaying HTML?
1251 // this is too messy... - better to only do it on columsn you know are going to be too long
1252 //tooltip : (typeof(value) === 'object') ? '' : value,
1253 cls : rowcfg.rowClass + ' x-col-' + i,
1255 html: (typeof(value) === 'object') ? '' : value
1262 if(typeof(config.colspan) != 'undefined'){
1263 td.colspan = config.colspan;
1268 if(typeof(config.align) != 'undefined' && config.align.length){
1269 td.style += ' text-align:' + config.align + ';';
1271 if(typeof(config.valign) != 'undefined' && config.valign.length){
1272 td.style += ' vertical-align:' + config.valign + ';';
1275 if(typeof(config.width) != 'undefined'){
1276 td.style += ' width:' + config.width + 'px;';
1280 if(typeof(config.cursor) != 'undefined'){
1281 td.style += ' cursor:' + config.cursor + ';';
1284 if(typeof(config.cls) != 'undefined'){
1285 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
1287 if (this.responsive) {
1288 ['xs','sm','md','lg'].map(function(size){
1290 if(typeof(config[size]) == 'undefined'){
1296 if (!config[size]) { // 0 = hidden
1297 // BS 4 '0' is treated as hide that column and below.
1298 td.cls += ' hidden-' + size + ' hidden' + size + '-down';
1302 td.cls += ' col-' + size + '-' + config[size] + (
1303 size == 'xs' ? (' col-' + config[size] ) : '' // bs4 col-{num} replaces col-xs
1313 row.cellObjects = cellObjects;
1321 onBeforeLoad : function()
1323 this.el.unmask(); // if needed.
1330 this.el.select('tbody', true).first().dom.innerHTML = '';
1333 * Show or hide a row.
1334 * @param {Number} rowIndex to show or hide
1335 * @param {Boolean} state hide
1337 setRowVisibility : function(rowIndex, state)
1339 var bt = this.bodyEl.dom;
1341 var rows = this.el.select('tbody > tr', true).elements;
1343 if(typeof(rows[rowIndex]) == 'undefined'){
1346 rows[rowIndex][ state ? 'removeClass' : 'addClass']('d-none');
1351 getSelectionModel : function(){
1353 this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
1355 return this.selModel;
1358 * Render the Roo.bootstrap object from renderder
1360 renderCellObject : function(r)
1364 r.cfg.parentId = (typeof(r.container) == 'string') ? r.container : r.container.id;
1366 var t = r.cfg.render(r.container);
1369 Roo.each(r.cfg.cn, function(c){
1371 container: t.getChildContainer(),
1374 _this.renderCellObject(child);
1379 * get the Row Index from a dom element.
1380 * @param {Roo.Element} row The row to look for
1381 * @returns {Number} the row
1383 getRowIndex : function(row)
1387 Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
1398 * get the header TH element for columnIndex
1399 * @param {Number} columnIndex
1400 * @returns {Roo.Element}
1402 getHeaderIndex: function(colIndex)
1404 var cols = this.headEl.select('th', true).elements;
1405 return cols[colIndex];
1408 * get the Column Index from a dom element. (using regex on x-hcol-{colid})
1409 * @param {domElement} cell to look for
1410 * @returns {Number} the column
1412 getCellIndex : function(cell)
1414 var id = String(cell.className).match(Roo.bootstrap.Table.cellRE);
1416 return parseInt(id[1], 10);
1421 * Returns the grid's underlying element = used by panel.Grid
1422 * @return {Element} The element
1424 getGridEl : function(){
1428 * Forces a resize - used by panel.Grid
1429 * @return {Element} The element
1431 autoSize : function()
1433 //var ctr = Roo.get(this.container.dom.parentElement);
1434 var ctr = Roo.get(this.el.dom);
1436 var thd = this.getGridEl().select('thead',true).first();
1437 var tbd = this.getGridEl().select('tbody', true).first();
1438 var tfd = this.getGridEl().select('tfoot', true).first();
1440 var cw = ctr.getWidth();
1441 this.getGridEl().select('tfoot tr, tfoot td',true).setWidth(cw);
1445 tbd.setWidth(ctr.getWidth());
1446 // if the body has a max height - and then scrolls - we should perhaps set up the height here
1447 // this needs fixing for various usage - currently only hydra job advers I think..
1449 // ctr.getHeight() - ((thd ? thd.getHeight() : 0) + (tfd ? tfd.getHeight() : 0))
1451 var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
1454 cw = Math.max(cw, this.totalWidth);
1455 this.getGridEl().select('tbody tr',true).setWidth(cw);
1458 // resize 'expandable coloumn?
1460 return; // we doe not have a view in this design..
1463 onBodyScroll: function()
1465 //Roo.log("body scrolled');" + this.bodyEl.dom.scrollLeft);
1467 this.headEl.setStyle({
1468 'position' : 'relative',
1469 'left': (-1* this.bodyEl.dom.scrollLeft) + 'px'
1475 var scrollHeight = this.bodyEl.dom.scrollHeight;
1477 var scrollTop = Math.ceil(this.bodyEl.getScroll().top);
1479 var height = this.bodyEl.getHeight();
1481 if(scrollHeight - height == scrollTop) {
1483 var total = this.ds.getTotalCount();
1485 if(this.footer.cursor + this.footer.pageSize < total){
1487 this.footer.ds.load({
1489 start : this.footer.cursor + this.footer.pageSize,
1490 limit : this.footer.pageSize
1499 onColumnSplitterMoved : function(i, diff)
1501 this.userResized = true;
1503 var cm = this.colModel;
1505 var w = this.getHeaderIndex(i).getWidth() + diff;
1508 cm.setColumnWidth(i, w, true);
1510 //var cid = cm.getColumnId(i); << not used in this version?
1511 /* Roo.log(['#' + this.id + ' .x-col-' + i, "width", w + "px"]);
1513 this.CSS.updateRule( '#' + this.id + ' .x-col-' + i, "width", w + "px");
1514 this.CSS.updateRule('#' + this.id + ' .x-hcol-' + i, "width", w + "px");
1515 this.CSS.updateRule('#' + this.id + ' .x-grid-split-' + i, "left", w + "px");
1517 //this.updateSplitters();
1518 //this.layout(); << ??
1519 this.fireEvent("columnresize", i, w);
1521 onHeaderChange : function()
1523 var header = this.renderHeader();
1524 var table = this.el.select('table', true).first();
1526 this.headEl.remove();
1527 this.headEl = table.createChild(header, this.bodyEl, false);
1529 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
1530 e.on('click', this.sort, this);
1533 if(this.enableColumnResize !== false && Roo.grid.SplitDragZone){
1534 new Roo.grid.SplitDragZone(this, this.headEl.dom, false); // not sure what 'lockedHd is for this implementation..)
1539 onHiddenChange : function(colModel, colIndex, hidden)
1543 var thSelector = '#' + this.id + ' .x-hcol-' + colIndex;
1544 var tdSelector = '#' + this.id + ' .x-col-' + colIndex;
1546 this.CSS.updateRule(thSelector, "display", "");
1547 this.CSS.updateRule(tdSelector, "display", "");
1550 this.CSS.updateRule(thSelector, "display", "none");
1551 this.CSS.updateRule(tdSelector, "display", "none");
1554 // onload calls initCSS()
1555 this.onHeaderChange();
1559 setColumnWidth: function(col_index, width)
1561 // width = "md-2 xs-2..."
1562 if(!this.colModel.config[col_index]) {
1566 var w = width.split(" ");
1568 var rows = this.el.dom.getElementsByClassName("x-col-"+col_index);
1570 var h_row = this.el.dom.getElementsByClassName("x-hcol-"+col_index);
1573 for(var j = 0; j < w.length; j++) {
1579 var size_cls = w[j].split("-");
1581 if(!Number.isInteger(size_cls[1] * 1)) {
1585 if(!this.colModel.config[col_index][size_cls[0]]) {
1589 if(!h_row[0].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
1593 h_row[0].classList.replace(
1594 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
1595 "col-"+size_cls[0]+"-"+size_cls[1]
1598 for(var i = 0; i < rows.length; i++) {
1600 var size_cls = w[j].split("-");
1602 if(!Number.isInteger(size_cls[1] * 1)) {
1606 if(!this.colModel.config[col_index][size_cls[0]]) {
1610 if(!rows[i].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
1614 rows[i].classList.replace(
1615 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
1616 "col-"+size_cls[0]+"-"+size_cls[1]
1620 this.colModel.config[col_index][size_cls[0]] = size_cls[1];
1625 // currently only used to find the split on drag..
1626 Roo.bootstrap.Table.cellRE = /(?:.*?)x-grid-(?:hd|cell|split)-([\d]+)(?:.*?)/;
1631 Roo.bootstrap.Table.AbstractSelectionModel = Roo.grid.AbstractSelectionModel;
1632 Roo.bootstrap.Table.RowSelectionModel = Roo.grid.RowSelectionModel;