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,
270 rowSelection : false,
271 cellSelection : false,
276 // Roo.Element - the tbody
277 bodyEl: false, // <tbody> Roo.Element - thead element
278 headEl: false, // <thead> Roo.Element - thead element
279 resizeProxy : false, // proxy element for dragging?
283 container: false, // used by gridpanel...
289 auto_hide_footer : false,
291 view: false, // actually points to this..
293 getAutoCreate : function()
295 var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
302 // this get's auto added by panel.Grid
303 if (this.scrollBody) {
304 cfg.cls += ' table-body-fixed';
307 cfg.cls += ' table-striped';
311 cfg.cls += ' table-hover';
314 cfg.cls += ' table-bordered';
316 if (this.condensed) {
317 cfg.cls += ' table-condensed';
320 if (this.responsive) {
321 cfg.cls += ' table-responsive';
325 cfg.cls+= ' ' +this.cls;
331 cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
334 if(this.store || this.cm){
336 cfg.cn.push(this.renderHeader());
339 cfg.cn.push(this.renderBody());
342 cfg.cn.push(this.renderFooter());
344 // where does this come from?
345 //cfg.cls+= ' TableGrid';
348 return { cn : [ cfg ] };
351 initEvents : function()
353 if(!this.store || !this.cm){
357 this.selModel.initEvents();
361 //Roo.log('initEvents with ds!!!!');
363 this.bodyEl = this.el.select('tbody', true).first();
364 this.headEl = this.el.select('thead', true).first();
365 this.mainFoot = this.el.select('tfoot', true).first();
370 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
371 e.on('click', this.sort, this);
375 // why is this done????? = it breaks dialogs??
376 //this.parent().el.setStyle('position', 'relative');
380 this.footer.parentId = this.id;
381 this.footer.onRender(this.el.select('tfoot tr td').first(), null);
384 this.el.select('tfoot tr td').first().addClass('hide');
389 this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
392 this.store.on('load', this.onLoad, this);
393 this.store.on('beforeload', this.onBeforeLoad, this);
394 this.store.on('update', this.onUpdate, this);
395 this.store.on('add', this.onAdd, this);
396 this.store.on("clear", this.clear, this);
398 this.el.on("contextmenu", this.onContextMenu, this);
401 this.cm.on("headerchange", this.onHeaderChange, this);
402 this.cm.on("hiddenchange", this.onHiddenChange, this, arguments);
404 //?? does bodyEl get replaced on render?
405 this.bodyEl.on("click", this.onClick, this);
406 this.bodyEl.on("dblclick", this.onDblClick, this);
407 this.bodyEl.on('scroll', this.onBodyScroll, this);
409 // guessing mainbody will work - this relays usually caught by selmodel at present.
410 this.relayEvents(this.bodyEl, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
413 this.resizeProxy = Roo.get(document.body).createChild({ cls:"x-grid-resize-proxy", html: ' ' });
416 if(this.headEl && this.enableColumnResize !== false && Roo.grid.SplitDragZone){
417 new Roo.grid.SplitDragZone(this, this.headEl.dom, false); // not sure what 'lockedHd is for this implementation..)
422 // Compatibility with grid - we implement all the view features at present.
432 var cm = this.cm, styles = [];
433 this.CSS.removeStyleSheet(this.id + '-cssrules');
434 var headHeight = this.headEl ? this.headEl.dom.clientHeight : 0;
435 // we can honour xs/sm/md/xl as widths...
436 // we first have to decide what widht we are currently at...
437 var sz = Roo.getGridSize();
441 var cols = []; // visable cols.
443 for(var i = 0, len = cm.getColumnCount(); i < len; i++) {
444 var w = cm.getColumnWidth(i, false);
446 cols.push( { rel : false, abs : 0 });
450 cols.push( { rel : false, abs : w });
452 last = i; // not really..
455 var w = cm.getColumnWidth(i, sz);
460 cols.push( { rel : w, abs : false });
463 var avail = this.bodyEl.dom.clientWidth - total_abs;
465 var unitWidth = Math.floor(avail / total);
466 var rem = avail - (unitWidth * total);
468 var hidden, width, pos = 0 , splithide , left;
469 for(var i = 0, len = cm.getColumnCount(); i < len; i++) {
471 hidden = 'display:none;';
473 width = 'width:0px;';
479 // we can honour xs/sm/md/xl ?
480 var w = cols[i].rel == false ? cols[i].abs : (cols[i].rel * unitWidth);
482 hidden = 'display:none;';
484 // width should return a small number...
486 w+=rem; // add the remaining with..
489 left = "left:" + (pos -4) + "px;";
490 width = "width:" + w+ "px;";
493 if (this.responsive) {
496 hidden = cm.isHidden(i) ? 'display:none;' : '';
497 splithide = 'display: none;';
500 styles.push( '#' , this.id , ' .x-col-' , i, " {", cm.config[i].css, width, hidden, "}\n" );
503 splithide = 'display:none;';
506 styles.push('#' , this.id , ' .x-hcol-' , i, " { ", width, hidden," }\n",
507 '#' , this.id , ' .x-grid-split-' , i, " { ", left, splithide, 'height:', (headHeight - 4), "px;}\n",
508 // this is the popover version..
509 '.popover-inner #' , this.id , ' .x-grid-split-' , i, " { ", left, splithide, 'height:', 100, "%;}\n"
514 //Roo.log(styles.join(''));
515 this.CSS.createStyleSheet( styles.join(''), this.id + '-cssrules');
521 onContextMenu : function(e, t)
523 this.processEvent("contextmenu", e);
526 processEvent : function(name, e)
528 if (name != 'touchstart' ) {
529 this.fireEvent(name, e);
532 var t = e.getTarget();
534 var cell = Roo.get(t);
540 if(cell.findParent('tfoot', false, true)){
544 if(cell.findParent('thead', false, true)){
546 if(e.getTarget().nodeName.toLowerCase() != 'th'){
547 cell = Roo.get(t).findParent('th', false, true);
549 Roo.log("failed to find th in thead?");
550 Roo.log(e.getTarget());
555 var cellIndex = cell.dom.cellIndex;
557 var ename = name == 'touchstart' ? 'click' : name;
558 this.fireEvent("header" + ename, this, cellIndex, e);
563 if(e.getTarget().nodeName.toLowerCase() != 'td'){
564 cell = Roo.get(t).findParent('td', false, true);
566 Roo.log("failed to find th in tbody?");
567 Roo.log(e.getTarget());
572 var row = cell.findParent('tr', false, true);
573 var cellIndex = cell.dom.cellIndex;
574 var rowIndex = row.dom.rowIndex - 1;
578 this.fireEvent("row" + name, this, rowIndex, e);
582 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
588 onMouseover : function(e, el)
590 var cell = Roo.get(el);
596 if(e.getTarget().nodeName.toLowerCase() != 'td'){
597 cell = cell.findParent('td', false, true);
600 var row = cell.findParent('tr', false, true);
601 var cellIndex = cell.dom.cellIndex;
602 var rowIndex = row.dom.rowIndex - 1; // start from 0
604 this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
608 onMouseout : function(e, el)
610 var cell = Roo.get(el);
616 if(e.getTarget().nodeName.toLowerCase() != 'td'){
617 cell = cell.findParent('td', false, true);
620 var row = cell.findParent('tr', false, true);
621 var cellIndex = cell.dom.cellIndex;
622 var rowIndex = row.dom.rowIndex - 1; // start from 0
624 this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
628 onClick : function(e, el)
630 var cell = Roo.get(el);
632 if(!cell || (!this.cellSelection && !this.rowSelection)){
636 if(e.getTarget().nodeName.toLowerCase() != 'td'){
637 cell = cell.findParent('td', false, true);
640 if(!cell || typeof(cell) == 'undefined'){
644 var row = cell.findParent('tr', false, true);
646 if(!row || typeof(row) == 'undefined'){
650 var cellIndex = cell.dom.cellIndex;
651 var rowIndex = this.getRowIndex(row);
653 // why??? - should these not be based on SelectionModel?
654 //if(this.cellSelection){
655 this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
658 //if(this.rowSelection){
659 this.fireEvent('rowclick', this, row, rowIndex, e);
664 onDblClick : function(e,el)
666 var cell = Roo.get(el);
668 if(!cell || (!this.cellSelection && !this.rowSelection)){
672 if(e.getTarget().nodeName.toLowerCase() != 'td'){
673 cell = cell.findParent('td', false, true);
676 if(!cell || typeof(cell) == 'undefined'){
680 var row = cell.findParent('tr', false, true);
682 if(!row || typeof(row) == 'undefined'){
686 var cellIndex = cell.dom.cellIndex;
687 var rowIndex = this.getRowIndex(row);
689 if(this.cellSelection){
690 this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
693 if(this.rowSelection){
694 this.fireEvent('rowdblclick', this, row, rowIndex, e);
697 findRowIndex : function(el)
699 var cell = Roo.get(el);
703 var row = cell.findParent('tr', false, true);
705 if(!row || typeof(row) == 'undefined'){
708 return this.getRowIndex(row);
710 sort : function(e,el)
712 var col = Roo.get(el);
714 if(!col.hasClass('sortable')){
718 var sort = col.attr('sort');
721 if(col.select('i', true).first().hasClass('fa-arrow-up')){
725 this.store.sortInfo = {field : sort, direction : dir};
728 Roo.log("calling footer first");
729 this.footer.onClick('first');
732 this.store.load({ params : { start : 0 } });
736 renderHeader : function()
746 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
748 var config = cm.config[i];
755 html: cm.getColumnHeader(i)
758 var tooltip = cm.getColumnTooltip(i);
766 if(typeof(config.sortable) != 'undefined' && config.sortable){
767 c.cls += ' sortable';
768 c.html = '<i class="fa"></i>' + c.html;
771 // could use BS4 hidden-..-down
773 if(typeof(config.lgHeader) != 'undefined'){
774 hh += '<span class="hidden-xs hidden-sm hidden-md ">' + config.lgHeader + '</span>';
777 if(typeof(config.mdHeader) != 'undefined'){
778 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
781 if(typeof(config.smHeader) != 'undefined'){
782 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
785 if(typeof(config.xsHeader) != 'undefined'){
786 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
793 if(typeof(config.tooltip) != 'undefined'){
794 c.tooltip = config.tooltip;
797 if(typeof(config.colspan) != 'undefined'){
798 c.colspan = config.colspan;
801 // hidden is handled by CSS now
803 if(typeof(config.dataIndex) != 'undefined'){
804 c.sort = config.dataIndex;
809 if(typeof(config.align) != 'undefined' && config.align.length){
810 c.style += ' text-align:' + config.align + ';';
813 /* width is done in CSS
814 *if(typeof(config.width) != 'undefined'){
815 c.style += ' width:' + config.width + 'px;';
816 this.totalWidth += config.width;
818 this.totalWidth += 100; // assume minimum of 100 per column?
822 if(typeof(config.cls) != 'undefined'){
823 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
825 // this is the bit that doesnt reall work at all...
827 if (this.responsive) {
830 ['xs','sm','md','lg'].map(function(size){
832 if(typeof(config[size]) == 'undefined'){
836 if (!config[size]) { // 0 = hidden
837 // BS 4 '0' is treated as hide that column and below.
838 c.cls += ' hidden-' + size + ' hidden' + size + '-down';
842 c.cls += ' col-' + size + '-' + config[size] + (
843 size == 'xs' ? (' col-' + config[size] ) : '' // bs4 col-{num} replaces col-xs
851 c.html +=' <span class="x-grid-split x-grid-split-' + i + '"></span>';
862 renderBody : function()
872 colspan : this.cm.getColumnCount()
882 renderFooter : function()
892 colspan : this.cm.getColumnCount()
906 // Roo.log('ds onload');
913 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
914 e.select('i', true).removeClass(['fa-arrow-up', 'fa-arrow-down']);
915 if (_this.store.sortInfo) {
917 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
918 e.select('i', true).addClass(['fa-arrow-up']);
921 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
922 e.select('i', true).addClass(['fa-arrow-down']);
927 var tbody = this.bodyEl;
929 if(ds.getCount() > 0){
930 ds.data.each(function(d,rowIndex){
931 var row = this.renderRow(cm, ds, rowIndex);
933 tbody.createChild(row);
937 if(row.cellObjects.length){
938 Roo.each(row.cellObjects, function(r){
939 _this.renderCellObject(r);
944 } else if (this.empty_results.length) {
945 this.el.mask(this.empty_results, 'no-spinner');
948 var tfoot = this.el.select('tfoot', true).first();
950 if(this.footerShow && this.auto_hide_footer && this.mainFoot){
952 this.mainFoot.setVisibilityMode(Roo.Element.DISPLAY).hide();
954 var total = this.ds.getTotalCount();
956 if(this.footer.pageSize < total){
957 this.mainFoot.show();
961 Roo.each(this.el.select('tbody td', true).elements, function(e){
962 e.on('mouseover', _this.onMouseover, _this);
965 Roo.each(this.el.select('tbody td', true).elements, function(e){
966 e.on('mouseout', _this.onMouseout, _this);
968 this.fireEvent('rowsrendered', this);
972 this.initCSS(); /// resize cols
978 onUpdate : function(ds,record)
980 this.refreshRow(record);
984 onRemove : function(ds, record, index, isUpdate){
985 if(isUpdate !== true){
986 this.fireEvent("beforerowremoved", this, index, record);
988 var bt = this.bodyEl.dom;
990 var rows = this.el.select('tbody > tr', true).elements;
992 if(typeof(rows[index]) != 'undefined'){
993 bt.removeChild(rows[index].dom);
996 // if(bt.rows[index]){
997 // bt.removeChild(bt.rows[index]);
1000 if(isUpdate !== true){
1001 //this.stripeRows(index);
1002 //this.syncRowHeights(index, index);
1004 this.fireEvent("rowremoved", this, index, record);
1008 onAdd : function(ds, records, rowIndex)
1010 //Roo.log('on Add called');
1011 // - note this does not handle multiple adding very well..
1012 var bt = this.bodyEl.dom;
1013 for (var i =0 ; i < records.length;i++) {
1014 //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
1015 //Roo.log(records[i]);
1016 //Roo.log(this.store.getAt(rowIndex+i));
1017 this.insertRow(this.store, rowIndex + i, false);
1024 refreshRow : function(record){
1025 var ds = this.store, index;
1026 if(typeof record == 'number'){
1028 record = ds.getAt(index);
1030 index = ds.indexOf(record);
1032 return; // should not happen - but seems to
1035 this.insertRow(ds, index, true);
1037 this.onRemove(ds, record, index+1, true);
1039 //this.syncRowHeights(index, index);
1041 this.fireEvent("rowupdated", this, index, record);
1043 // private - called by RowSelection
1044 onRowSelect : function(rowIndex){
1045 var row = this.getRowDom(rowIndex);
1046 row.addClass(['bg-info','info']);
1048 // private - called by RowSelection
1049 onRowDeselect : function(rowIndex)
1054 var row = this.getRowDom(rowIndex);
1055 row.removeClass(['bg-info','info']);
1058 * Focuses the specified row.
1059 * @param {Number} row The row index
1061 focusRow : function(row)
1063 //Roo.log('GridView.focusRow');
1064 var x = this.bodyEl.dom.scrollLeft;
1065 this.focusCell(row, 0, false);
1066 this.bodyEl.dom.scrollLeft = x;
1070 * Focuses the specified cell.
1071 * @param {Number} row The row index
1072 * @param {Number} col The column index
1073 * @param {Boolean} hscroll false to disable horizontal scrolling
1075 focusCell : function(row, col, hscroll)
1077 //Roo.log('GridView.focusCell');
1078 var el = this.ensureVisible(row, col, hscroll);
1079 // not sure what focusEL achives = it's a <a> pos relative
1080 //this.focusEl.alignTo(el, "tl-tl");
1082 // this.focusEl.focus();
1084 // this.focusEl.focus.defer(1, this.focusEl);
1089 * Scrolls the specified cell into view
1090 * @param {Number} row The row index
1091 * @param {Number} col The column index
1092 * @param {Boolean} hscroll false to disable horizontal scrolling
1094 ensureVisible : function(row, col, hscroll)
1096 //Roo.log('GridView.ensureVisible,' + row + ',' + col);
1097 //return null; //disable for testing.
1098 if(typeof row != "number"){
1101 if(row < 0 && row >= this.ds.getCount()){
1104 col = (col !== undefined ? col : 0);
1106 while(cm.isHidden(col)){
1110 var el = this.getCellDom(row, col);
1114 var c = this.bodyEl.dom;
1116 var ctop = parseInt(el.offsetTop, 10);
1117 var cleft = parseInt(el.offsetLeft, 10);
1118 var cbot = ctop + el.offsetHeight;
1119 var cright = cleft + el.offsetWidth;
1121 //var ch = c.clientHeight - this.mainHd.dom.offsetHeight;
1122 var ch = 0; //?? header is not withing the area?
1123 var stop = parseInt(c.scrollTop, 10);
1124 var sleft = parseInt(c.scrollLeft, 10);
1125 var sbot = stop + ch;
1126 var sright = sleft + c.clientWidth;
1128 Roo.log('GridView.ensureVisible:' +
1130 ' c.clientHeight:' + c.clientHeight +
1131 ' this.mainHd.dom.offsetHeight:' + this.mainHd.dom.offsetHeight +
1140 //Roo.log("set scrolltop to ctop DISABLE?");
1141 }else if(cbot > sbot){
1142 //Roo.log("set scrolltop to cbot-ch");
1143 c.scrollTop = cbot-ch;
1146 if(hscroll !== false){
1148 c.scrollLeft = cleft;
1149 }else if(cright > sright){
1150 c.scrollLeft = cright-c.clientWidth;
1158 insertRow : function(dm, rowIndex, isUpdate){
1161 this.fireEvent("beforerowsinserted", this, rowIndex);
1163 //var s = this.getScrollState();
1164 var row = this.renderRow(this.cm, this.store, rowIndex);
1165 // insert before rowIndex..
1166 var e = this.bodyEl.createChild(row,this.getRowDom(rowIndex));
1170 if(row.cellObjects.length){
1171 Roo.each(row.cellObjects, function(r){
1172 _this.renderCellObject(r);
1177 this.fireEvent("rowsinserted", this, rowIndex);
1178 //this.syncRowHeights(firstRow, lastRow);
1179 //this.stripeRows(firstRow);
1186 getRowDom : function(rowIndex)
1188 var rows = this.el.select('tbody > tr', true).elements;
1190 return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
1193 getCellDom : function(rowIndex, colIndex)
1195 var row = this.getRowDom(rowIndex);
1196 if (row === false) {
1199 var cols = row.select('td', true).elements;
1200 return (typeof(cols[colIndex]) == 'undefined') ? false : cols[colIndex];
1204 // returns the object tree for a tr..
1207 renderRow : function(cm, ds, rowIndex)
1209 var d = ds.getAt(rowIndex);
1213 cls : 'x-row-' + rowIndex,
1217 var cellObjects = [];
1219 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
1220 var config = cm.config[i];
1222 var renderer = cm.getRenderer(i);
1226 if(typeof(renderer) !== 'undefined'){
1227 value = renderer(d.data[cm.getDataIndex(i)], false, d);
1229 // if object are returned, then they are expected to be Roo.bootstrap.Component instances
1230 // and are rendered into the cells after the row is rendered - using the id for the element.
1232 if(typeof(value) === 'object'){
1242 rowIndex : rowIndex,
1247 this.fireEvent('rowclass', this, rowcfg);
1251 // this might end up displaying HTML?
1252 // this is too messy... - better to only do it on columsn you know are going to be too long
1253 //tooltip : (typeof(value) === 'object') ? '' : value,
1254 cls : rowcfg.rowClass + ' x-col-' + i,
1256 html: (typeof(value) === 'object') ? '' : value
1263 if(typeof(config.colspan) != 'undefined'){
1264 td.colspan = config.colspan;
1269 if(typeof(config.align) != 'undefined' && config.align.length){
1270 td.style += ' text-align:' + config.align + ';';
1272 if(typeof(config.valign) != 'undefined' && config.valign.length){
1273 td.style += ' vertical-align:' + config.valign + ';';
1276 if(typeof(config.width) != 'undefined'){
1277 td.style += ' width:' + config.width + 'px;';
1281 if(typeof(config.cursor) != 'undefined'){
1282 td.style += ' cursor:' + config.cursor + ';';
1285 if(typeof(config.cls) != 'undefined'){
1286 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
1288 if (this.responsive) {
1289 ['xs','sm','md','lg'].map(function(size){
1291 if(typeof(config[size]) == 'undefined'){
1297 if (!config[size]) { // 0 = hidden
1298 // BS 4 '0' is treated as hide that column and below.
1299 td.cls += ' hidden-' + size + ' hidden' + size + '-down';
1303 td.cls += ' col-' + size + '-' + config[size] + (
1304 size == 'xs' ? (' col-' + config[size] ) : '' // bs4 col-{num} replaces col-xs
1314 row.cellObjects = cellObjects;
1322 onBeforeLoad : function()
1324 this.el.unmask(); // if needed.
1331 this.el.select('tbody', true).first().dom.innerHTML = '';
1334 * Show or hide a row.
1335 * @param {Number} rowIndex to show or hide
1336 * @param {Boolean} state hide
1338 setRowVisibility : function(rowIndex, state)
1340 var bt = this.bodyEl.dom;
1342 var rows = this.el.select('tbody > tr', true).elements;
1344 if(typeof(rows[rowIndex]) == 'undefined'){
1347 rows[rowIndex][ state ? 'removeClass' : 'addClass']('d-none');
1352 getSelectionModel : function(){
1354 this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
1356 return this.selModel;
1359 * Render the Roo.bootstrap object from renderder
1361 renderCellObject : function(r)
1365 r.cfg.parentId = (typeof(r.container) == 'string') ? r.container : r.container.id;
1367 var t = r.cfg.render(r.container);
1370 Roo.each(r.cfg.cn, function(c){
1372 container: t.getChildContainer(),
1375 _this.renderCellObject(child);
1380 * get the Row Index from a dom element.
1381 * @param {Roo.Element} row The row to look for
1382 * @returns {Number} the row
1384 getRowIndex : function(row)
1388 Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
1399 * get the header TH element for columnIndex
1400 * @param {Number} columnIndex
1401 * @returns {Roo.Element}
1403 getHeaderIndex: function(colIndex)
1405 var cols = this.headEl.select('th', true).elements;
1406 return cols[colIndex];
1409 * get the Column Index from a dom element. (using regex on x-hcol-{colid})
1410 * @param {domElement} cell to look for
1411 * @returns {Number} the column
1413 getCellIndex : function(cell)
1415 var id = String(cell.className).match(Roo.bootstrap.Table.cellRE);
1417 return parseInt(id[1], 10);
1422 * Returns the grid's underlying element = used by panel.Grid
1423 * @return {Element} The element
1425 getGridEl : function(){
1429 * Forces a resize - used by panel.Grid
1430 * @return {Element} The element
1432 autoSize : function()
1434 //var ctr = Roo.get(this.container.dom.parentElement);
1435 var ctr = Roo.get(this.el.dom);
1437 var thd = this.getGridEl().select('thead',true).first();
1438 var tbd = this.getGridEl().select('tbody', true).first();
1439 var tfd = this.getGridEl().select('tfoot', true).first();
1441 var cw = ctr.getWidth();
1442 this.getGridEl().select('tfoot tr, tfoot td',true).setWidth(cw);
1446 tbd.setWidth(ctr.getWidth());
1447 // if the body has a max height - and then scrolls - we should perhaps set up the height here
1448 // this needs fixing for various usage - currently only hydra job advers I think..
1450 // ctr.getHeight() - ((thd ? thd.getHeight() : 0) + (tfd ? tfd.getHeight() : 0))
1452 var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
1455 cw = Math.max(cw, this.totalWidth);
1456 this.getGridEl().select('tbody tr',true).setWidth(cw);
1459 // resize 'expandable coloumn?
1461 return; // we doe not have a view in this design..
1464 onBodyScroll: function()
1466 //Roo.log("body scrolled');" + this.bodyEl.dom.scrollLeft);
1468 this.headEl.setStyle({
1469 'position' : 'relative',
1470 'left': (-1* this.bodyEl.dom.scrollLeft) + 'px'
1476 var scrollHeight = this.bodyEl.dom.scrollHeight;
1478 var scrollTop = Math.ceil(this.bodyEl.getScroll().top);
1480 var height = this.bodyEl.getHeight();
1482 if(scrollHeight - height == scrollTop) {
1484 var total = this.ds.getTotalCount();
1486 if(this.footer.cursor + this.footer.pageSize < total){
1488 this.footer.ds.load({
1490 start : this.footer.cursor + this.footer.pageSize,
1491 limit : this.footer.pageSize
1500 onColumnSplitterMoved : function(i, diff)
1502 this.userResized = true;
1504 var cm = this.colModel;
1506 var w = this.getHeaderIndex(i).getWidth() + diff;
1509 cm.setColumnWidth(i, w, true);
1511 //var cid = cm.getColumnId(i); << not used in this version?
1512 /* Roo.log(['#' + this.id + ' .x-col-' + i, "width", w + "px"]);
1514 this.CSS.updateRule( '#' + this.id + ' .x-col-' + i, "width", w + "px");
1515 this.CSS.updateRule('#' + this.id + ' .x-hcol-' + i, "width", w + "px");
1516 this.CSS.updateRule('#' + this.id + ' .x-grid-split-' + i, "left", w + "px");
1518 //this.updateSplitters();
1519 //this.layout(); << ??
1520 this.fireEvent("columnresize", i, w);
1522 onHeaderChange : function()
1524 var header = this.renderHeader();
1525 var table = this.el.select('table', true).first();
1527 this.headEl.remove();
1528 this.headEl = table.createChild(header, this.bodyEl, false);
1530 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
1531 e.on('click', this.sort, this);
1534 if(this.enableColumnResize !== false && Roo.grid.SplitDragZone){
1535 new Roo.grid.SplitDragZone(this, this.headEl.dom, false); // not sure what 'lockedHd is for this implementation..)
1540 onHiddenChange : function(colModel, colIndex, hidden)
1544 var thSelector = '#' + this.id + ' .x-hcol-' + colIndex;
1545 var tdSelector = '#' + this.id + ' .x-col-' + colIndex;
1547 this.CSS.updateRule(thSelector, "display", "");
1548 this.CSS.updateRule(tdSelector, "display", "");
1551 this.CSS.updateRule(thSelector, "display", "none");
1552 this.CSS.updateRule(tdSelector, "display", "none");
1555 // onload calls initCSS()
1556 this.onHeaderChange();
1560 setColumnWidth: function(col_index, width)
1562 // width = "md-2 xs-2..."
1563 if(!this.colModel.config[col_index]) {
1567 var w = width.split(" ");
1569 var rows = this.el.dom.getElementsByClassName("x-col-"+col_index);
1571 var h_row = this.el.dom.getElementsByClassName("x-hcol-"+col_index);
1574 for(var j = 0; j < w.length; j++) {
1580 var size_cls = w[j].split("-");
1582 if(!Number.isInteger(size_cls[1] * 1)) {
1586 if(!this.colModel.config[col_index][size_cls[0]]) {
1590 if(!h_row[0].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
1594 h_row[0].classList.replace(
1595 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
1596 "col-"+size_cls[0]+"-"+size_cls[1]
1599 for(var i = 0; i < rows.length; i++) {
1601 var size_cls = w[j].split("-");
1603 if(!Number.isInteger(size_cls[1] * 1)) {
1607 if(!this.colModel.config[col_index][size_cls[0]]) {
1611 if(!rows[i].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
1615 rows[i].classList.replace(
1616 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
1617 "col-"+size_cls[0]+"-"+size_cls[1]
1621 this.colModel.config[col_index][size_cls[0]] = size_cls[1];
1626 // currently only used to find the split on drag..
1627 Roo.bootstrap.Table.cellRE = /(?:.*?)x-grid-(?:hd|cell|split)-([\d]+)(?:.*?)/;
1632 Roo.bootstrap.Table.AbstractSelectionModel = Roo.grid.AbstractSelectionModel;
1633 Roo.bootstrap.Table.RowSelectionModel = Roo.grid.RowSelectionModel;