ext-all-debug.js
资源名称:ext-3.1.0.zip [点击查看]
上传用户:dawnssy
上传日期:2022-08-06
资源大小:9345k
文件大小:1167k
源码类别:
JavaScript
开发平台:
JavaScript
- stripeRows : false,
- trackMouseOver : true,
- stateEvents : ['columnmove', 'columnresize', 'sortchange'],
- view : null,
- bubbleEvents: [],
- rendered : false,
- viewReady : false,
- initComponent : function(){
- Ext.grid.GridPanel.superclass.initComponent.call(this);
- if(this.columnLines){
- this.cls = (this.cls || '') + ' x-grid-with-col-lines';
- }
- this.autoScroll = false;
- this.autoWidth = false;
- if(Ext.isArray(this.columns)){
- this.colModel = new Ext.grid.ColumnModel(this.columns);
- delete this.columns;
- }
- if(this.ds){
- this.store = this.ds;
- delete this.ds;
- }
- if(this.cm){
- this.colModel = this.cm;
- delete this.cm;
- }
- if(this.sm){
- this.selModel = this.sm;
- delete this.sm;
- }
- this.store = Ext.StoreMgr.lookup(this.store);
- this.addEvents(
- 'click',
- 'dblclick',
- 'contextmenu',
- 'mousedown',
- 'mouseup',
- 'mouseover',
- 'mouseout',
- 'keypress',
- 'keydown',
- 'cellmousedown',
- 'rowmousedown',
- 'headermousedown',
- 'groupmousedown',
- 'rowbodymousedown',
- 'containermousedown',
- 'cellclick',
- 'celldblclick',
- 'rowclick',
- 'rowdblclick',
- 'headerclick',
- 'headerdblclick',
- 'groupclick',
- 'groupdblclick',
- 'containerclick',
- 'containerdblclick',
- 'rowbodyclick',
- 'rowbodydblclick',
- 'rowcontextmenu',
- 'cellcontextmenu',
- 'headercontextmenu',
- 'groupcontextmenu',
- 'containercontextmenu',
- 'rowbodycontextmenu',
- 'bodyscroll',
- 'columnresize',
- 'columnmove',
- 'sortchange',
- 'reconfigure',
- 'viewready'
- );
- },
- onRender : function(ct, position){
- Ext.grid.GridPanel.superclass.onRender.apply(this, arguments);
- var c = this.getGridEl();
- this.el.addClass('x-grid-panel');
- this.mon(c, {
- scope: this,
- mousedown: this.onMouseDown,
- click: this.onClick,
- dblclick: this.onDblClick,
- contextmenu: this.onContextMenu
- });
- this.relayEvents(c, ['mousedown','mouseup','mouseover','mouseout','keypress', 'keydown']);
- var view = this.getView();
- view.init(this);
- view.render();
- this.getSelectionModel().init(this);
- },
- initEvents : function(){
- Ext.grid.GridPanel.superclass.initEvents.call(this);
- if(this.loadMask){
- this.loadMask = new Ext.LoadMask(this.bwrap,
- Ext.apply({store:this.store}, this.loadMask));
- }
- },
- initStateEvents : function(){
- Ext.grid.GridPanel.superclass.initStateEvents.call(this);
- this.mon(this.colModel, 'hiddenchange', this.saveState, this, {delay: 100});
- },
- applyState : function(state){
- var cm = this.colModel,
- cs = state.columns;
- if(cs){
- for(var i = 0, len = cs.length; i < len; i++){
- var s = cs[i],
- c = cm.getColumnById(s.id);
- if(c){
- c.hidden = s.hidden;
- c.width = s.width;
- var oldIndex = cm.getIndexById(s.id);
- if(oldIndex != i){
- cm.moveColumn(oldIndex, i);
- }
- }
- }
- }
- if(state.sort && this.store){
- this.store[this.store.remoteSort ? 'setDefaultSort' : 'sort'](state.sort.field, state.sort.direction);
- }
- var o = Ext.apply({}, state);
- delete o.columns;
- delete o.sort;
- Ext.grid.GridPanel.superclass.applyState.call(this, o);
- },
- getState : function(){
- var o = {columns: []};
- for(var i = 0, c; (c = this.colModel.config[i]); i++){
- o.columns[i] = {
- id: c.id,
- width: c.width
- };
- if(c.hidden){
- o.columns[i].hidden = true;
- }
- }
- if(this.store){
- var ss = this.store.getSortState();
- if(ss){
- o.sort = ss;
- }
- }
- return o;
- },
- afterRender : function(){
- Ext.grid.GridPanel.superclass.afterRender.call(this);
- var v = this.view;
- this.on('bodyresize', v.layout, v);
- v.layout();
- if(this.deferRowRender){
- v.afterRender.defer(10, this.view);
- }else{
- v.afterRender();
- }
- this.viewReady = true;
- },
- reconfigure : function(store, colModel){
- var rendered = this.rendered;
- if(rendered){
- if(this.loadMask){
- this.loadMask.destroy();
- this.loadMask = new Ext.LoadMask(this.bwrap,
- Ext.apply({}, {store:store}, this.initialConfig.loadMask));
- }
- }
- if(this.view){
- this.view.initData(store, colModel);
- }
- this.store = store;
- this.colModel = colModel;
- if(rendered){
- this.view.refresh(true);
- }
- this.fireEvent('reconfigure', this, store, colModel);
- },
- onDestroy : function(){
- if(this.rendered){
- Ext.destroy(this.view, this.loadMask);
- }else if(this.store && this.store.autoDestroy){
- this.store.destroy();
- }
- Ext.destroy(this.colModel, this.selModel);
- this.store = this.selModel = this.colModel = this.view = this.loadMask = null;
- Ext.grid.GridPanel.superclass.onDestroy.call(this);
- },
- processEvent : function(name, e){
- this.fireEvent(name, e);
- var t = e.getTarget(),
- v = this.view,
- header = v.findHeaderIndex(t);
- if(header !== false){
- this.fireEvent('header' + name, this, header, e);
- }else{
- var row = v.findRowIndex(t),
- cell,
- body;
- if(row !== false){
- this.fireEvent('row' + name, this, row, e);
- cell = v.findCellIndex(t);
- body = v.findRowBody(t);
- if(cell !== false){
- this.fireEvent('cell' + name, this, row, cell, e);
- }
- if(body){
- this.fireEvent('rowbody' + name, this, row, e);
- }
- }else{
- this.fireEvent('container' + name, this, e);
- }
- }
- this.view.processEvent(name, e);
- },
- onClick : function(e){
- this.processEvent('click', e);
- },
- onMouseDown : function(e){
- this.processEvent('mousedown', e);
- },
- onContextMenu : function(e, t){
- this.processEvent('contextmenu', e);
- },
- onDblClick : function(e){
- this.processEvent('dblclick', e);
- },
- walkCells : function(row, col, step, fn, scope){
- var cm = this.colModel,
- clen = cm.getColumnCount(),
- ds = this.store,
- rlen = ds.getCount(),
- first = true;
- if(step < 0){
- if(col < 0){
- row--;
- first = false;
- }
- while(row >= 0){
- if(!first){
- col = clen-1;
- }
- first = false;
- while(col >= 0){
- if(fn.call(scope || this, row, col, cm) === true){
- return [row, col];
- }
- col--;
- }
- row--;
- }
- } else {
- if(col >= clen){
- row++;
- first = false;
- }
- while(row < rlen){
- if(!first){
- col = 0;
- }
- first = false;
- while(col < clen){
- if(fn.call(scope || this, row, col, cm) === true){
- return [row, col];
- }
- col++;
- }
- row++;
- }
- }
- return null;
- },
- onResize : function(){
- Ext.grid.GridPanel.superclass.onResize.apply(this, arguments);
- if(this.viewReady){
- this.view.layout();
- }
- },
- getGridEl : function(){
- return this.body;
- },
- stopEditing : Ext.emptyFn,
- getSelectionModel : function(){
- if(!this.selModel){
- this.selModel = new Ext.grid.RowSelectionModel(
- this.disableSelection ? {selectRow: Ext.emptyFn} : null);
- }
- return this.selModel;
- },
- getStore : function(){
- return this.store;
- },
- getColumnModel : function(){
- return this.colModel;
- },
- getView : function(){
- if(!this.view){
- this.view = new Ext.grid.GridView(this.viewConfig);
- }
- return this.view;
- },
- getDragDropText : function(){
- var count = this.selModel.getCount();
- return String.format(this.ddText, count, count == 1 ? '' : 's');
- }
- });
- Ext.reg('grid', Ext.grid.GridPanel);
- Ext.grid.GridView = Ext.extend(Ext.util.Observable, {
- deferEmptyText : true,
- scrollOffset : undefined,
- autoFill : false,
- forceFit : false,
- sortClasses : ['sort-asc', 'sort-desc'],
- sortAscText : 'Sort Ascending',
- sortDescText : 'Sort Descending',
- columnsText : 'Columns',
- selectedRowClass : 'x-grid3-row-selected',
- borderWidth : 2,
- tdClass : 'x-grid3-cell',
- hdCls : 'x-grid3-hd',
- markDirty : true,
- cellSelectorDepth : 4,
- rowSelectorDepth : 10,
- rowBodySelectorDepth : 10,
- cellSelector : 'td.x-grid3-cell',
- rowSelector : 'div.x-grid3-row',
- rowBodySelector : 'div.x-grid3-row-body',
- firstRowCls: 'x-grid3-row-first',
- lastRowCls: 'x-grid3-row-last',
- rowClsRe: /(?:^|s+)x-grid3-row-(first|last|alt)(?:s+|$)/g,
- constructor : function(config){
- Ext.apply(this, config);
- this.addEvents(
- 'beforerowremoved',
- 'beforerowsinserted',
- 'beforerefresh',
- 'rowremoved',
- 'rowsinserted',
- 'rowupdated',
- 'refresh'
- );
- Ext.grid.GridView.superclass.constructor.call(this);
- },
- initTemplates : function(){
- var ts = this.templates || {};
- if(!ts.master){
- ts.master = new Ext.Template(
- '<div class="x-grid3" hidefocus="true">',
- '<div class="x-grid3-viewport">',
- '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{ostyle}">{header}</div></div><div class="x-clear"></div></div>',
- '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
- '</div>',
- '<div class="x-grid3-resize-marker"> </div>',
- '<div class="x-grid3-resize-proxy"> </div>',
- '</div>'
- );
- }
- if(!ts.header){
- ts.header = new Ext.Template(
- '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
- '<thead><tr class="x-grid3-hd-row">{cells}</tr></thead>',
- '</table>'
- );
- }
- if(!ts.hcell){
- ts.hcell = new Ext.Template(
- '<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id} {css}" style="{style}"><div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">', this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
- '{value}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
- '</div></td>'
- );
- }
- if(!ts.body){
- ts.body = new Ext.Template('{rows}');
- }
- if(!ts.row){
- ts.row = new Ext.Template(
- '<div class="x-grid3-row {alt}" style="{tstyle}"><table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
- '<tbody><tr>{cells}</tr>',
- (this.enableRowBody ? '<tr class="x-grid3-row-body-tr" style="{bodyStyle}"><td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on"><div class="x-grid3-row-body">{body}</div></td></tr>' : ''),
- '</tbody></table></div>'
- );
- }
- if(!ts.cell){
- ts.cell = new Ext.Template(
- '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
- '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>',
- '</td>'
- );
- }
- for(var k in ts){
- var t = ts[k];
- if(t && Ext.isFunction(t.compile) && !t.compiled){
- t.disableFormats = true;
- t.compile();
- }
- }
- this.templates = ts;
- this.colRe = new RegExp('x-grid3-td-([^\s]+)', '');
- },
- fly : function(el){
- if(!this._flyweight){
- this._flyweight = new Ext.Element.Flyweight(document.body);
- }
- this._flyweight.dom = el;
- return this._flyweight;
- },
- getEditorParent : function(){
- return this.scroller.dom;
- },
- initElements : function(){
- var E = Ext.Element;
- var el = this.grid.getGridEl().dom.firstChild;
- var cs = el.childNodes;
- this.el = new E(el);
- this.mainWrap = new E(cs[0]);
- this.mainHd = new E(this.mainWrap.dom.firstChild);
- if(this.grid.hideHeaders){
- this.mainHd.setDisplayed(false);
- }
- this.innerHd = this.mainHd.dom.firstChild;
- this.scroller = new E(this.mainWrap.dom.childNodes[1]);
- if(this.forceFit){
- this.scroller.setStyle('overflow-x', 'hidden');
- }
- this.mainBody = new E(this.scroller.dom.firstChild);
- this.focusEl = new E(this.scroller.dom.childNodes[1]);
- this.focusEl.swallowEvent('click', true);
- this.resizeMarker = new E(cs[1]);
- this.resizeProxy = new E(cs[2]);
- },
- getRows : function(){
- return this.hasRows() ? this.mainBody.dom.childNodes : [];
- },
- findCell : function(el){
- if(!el){
- return false;
- }
- return this.fly(el).findParent(this.cellSelector, this.cellSelectorDepth);
- },
- findCellIndex : function(el, requiredCls){
- var cell = this.findCell(el);
- if(cell && (!requiredCls || this.fly(cell).hasClass(requiredCls))){
- return this.getCellIndex(cell);
- }
- return false;
- },
- getCellIndex : function(el){
- if(el){
- var m = el.className.match(this.colRe);
- if(m && m[1]){
- return this.cm.getIndexById(m[1]);
- }
- }
- return false;
- },
- findHeaderCell : function(el){
- var cell = this.findCell(el);
- return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null;
- },
- findHeaderIndex : function(el){
- return this.findCellIndex(el, this.hdCls);
- },
- findRow : function(el){
- if(!el){
- return false;
- }
- return this.fly(el).findParent(this.rowSelector, this.rowSelectorDepth);
- },
- findRowIndex : function(el){
- var r = this.findRow(el);
- return r ? r.rowIndex : false;
- },
- findRowBody : function(el){
- if(!el){
- return false;
- }
- return this.fly(el).findParent(this.rowBodySelector, this.rowBodySelectorDepth);
- },
- getRow : function(row){
- return this.getRows()[row];
- },
- getCell : function(row, col){
- return this.getRow(row).getElementsByTagName('td')[col];
- },
- getHeaderCell : function(index){
- return this.mainHd.dom.getElementsByTagName('td')[index];
- },
- addRowClass : function(row, cls){
- var r = this.getRow(row);
- if(r){
- this.fly(r).addClass(cls);
- }
- },
- removeRowClass : function(row, cls){
- var r = this.getRow(row);
- if(r){
- this.fly(r).removeClass(cls);
- }
- },
- removeRow : function(row){
- Ext.removeNode(this.getRow(row));
- this.syncFocusEl(row);
- },
- removeRows : function(firstRow, lastRow){
- var bd = this.mainBody.dom;
- for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
- Ext.removeNode(bd.childNodes[firstRow]);
- }
- this.syncFocusEl(firstRow);
- },
- getScrollState : function(){
- var sb = this.scroller.dom;
- return {left: sb.scrollLeft, top: sb.scrollTop};
- },
- restoreScroll : function(state){
- var sb = this.scroller.dom;
- sb.scrollLeft = state.left;
- sb.scrollTop = state.top;
- },
- scrollToTop : function(){
- this.scroller.dom.scrollTop = 0;
- this.scroller.dom.scrollLeft = 0;
- },
- syncScroll : function(){
- this.syncHeaderScroll();
- var mb = this.scroller.dom;
- this.grid.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
- },
- syncHeaderScroll : function(){
- var mb = this.scroller.dom;
- this.innerHd.scrollLeft = mb.scrollLeft;
- this.innerHd.scrollLeft = mb.scrollLeft;
- },
- updateSortIcon : function(col, dir){
- var sc = this.sortClasses;
- var hds = this.mainHd.select('td').removeClass(sc);
- hds.item(col).addClass(sc[dir == 'DESC' ? 1 : 0]);
- },
- updateAllColumnWidths : function(){
- var tw = this.getTotalWidth(),
- clen = this.cm.getColumnCount(),
- ws = [],
- len,
- i;
- for(i = 0; i < clen; i++){
- ws[i] = this.getColumnWidth(i);
- }
- this.innerHd.firstChild.style.width = this.getOffsetWidth();
- this.innerHd.firstChild.firstChild.style.width = tw;
- this.mainBody.dom.style.width = tw;
- for(i = 0; i < clen; i++){
- var hd = this.getHeaderCell(i);
- hd.style.width = ws[i];
- }
- var ns = this.getRows(), row, trow;
- for(i = 0, len = ns.length; i < len; i++){
- row = ns[i];
- row.style.width = tw;
- if(row.firstChild){
- row.firstChild.style.width = tw;
- trow = row.firstChild.rows[0];
- for (var j = 0; j < clen; j++) {
- trow.childNodes[j].style.width = ws[j];
- }
- }
- }
- this.onAllColumnWidthsUpdated(ws, tw);
- },
- updateColumnWidth : function(col, width){
- var w = this.getColumnWidth(col);
- var tw = this.getTotalWidth();
- this.innerHd.firstChild.style.width = this.getOffsetWidth();
- this.innerHd.firstChild.firstChild.style.width = tw;
- this.mainBody.dom.style.width = tw;
- var hd = this.getHeaderCell(col);
- hd.style.width = w;
- var ns = this.getRows(), row;
- for(var i = 0, len = ns.length; i < len; i++){
- row = ns[i];
- row.style.width = tw;
- if(row.firstChild){
- row.firstChild.style.width = tw;
- row.firstChild.rows[0].childNodes[col].style.width = w;
- }
- }
- this.onColumnWidthUpdated(col, w, tw);
- },
- updateColumnHidden : function(col, hidden){
- var tw = this.getTotalWidth();
- this.innerHd.firstChild.style.width = this.getOffsetWidth();
- this.innerHd.firstChild.firstChild.style.width = tw;
- this.mainBody.dom.style.width = tw;
- var display = hidden ? 'none' : '';
- var hd = this.getHeaderCell(col);
- hd.style.display = display;
- var ns = this.getRows(), row;
- for(var i = 0, len = ns.length; i < len; i++){
- row = ns[i];
- row.style.width = tw;
- if(row.firstChild){
- row.firstChild.style.width = tw;
- row.firstChild.rows[0].childNodes[col].style.display = display;
- }
- }
- this.onColumnHiddenUpdated(col, hidden, tw);
- delete this.lastViewWidth;
- this.layout();
- },
- doRender : function(cs, rs, ds, startRow, colCount, stripe){
- var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1;
- var tstyle = 'width:'+this.getTotalWidth()+';';
- var buf = [], cb, c, p = {}, rp = {tstyle: tstyle}, r;
- for(var j = 0, len = rs.length; j < len; j++){
- r = rs[j]; cb = [];
- var rowIndex = (j+startRow);
- for(var i = 0; i < colCount; i++){
- c = cs[i];
- p.id = c.id;
- p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
- p.attr = p.cellAttr = '';
- p.value = c.renderer.call(c.scope, r.data[c.name], p, r, rowIndex, i, ds);
- p.style = c.style;
- if(Ext.isEmpty(p.value)){
- p.value = ' ';
- }
- if(this.markDirty && r.dirty && Ext.isDefined(r.modified[c.name])){
- p.css += ' x-grid3-dirty-cell';
- }
- cb[cb.length] = ct.apply(p);
- }
- var alt = [];
- if(stripe && ((rowIndex+1) % 2 === 0)){
- alt[0] = 'x-grid3-row-alt';
- }
- if(r.dirty){
- alt[1] = ' x-grid3-dirty-row';
- }
- rp.cols = colCount;
- if(this.getRowClass){
- alt[2] = this.getRowClass(r, rowIndex, rp, ds);
- }
- rp.alt = alt.join(' ');
- rp.cells = cb.join('');
- buf[buf.length] = rt.apply(rp);
- }
- return buf.join('');
- },
- processRows : function(startRow, skipStripe){
- if(!this.ds || this.ds.getCount() < 1){
- return;
- }
- var rows = this.getRows(),
- len = rows.length,
- i, r;
- skipStripe = skipStripe || !this.grid.stripeRows;
- startRow = startRow || 0;
- for(i = 0; i<len; i++) {
- r = rows[i];
- if(r) {
- r.rowIndex = i;
- if(!skipStripe){
- r.className = r.className.replace(this.rowClsRe, ' ');
- if ((i + 1) % 2 === 0){
- r.className += ' x-grid3-row-alt';
- }
- }
- }
- }
- if(startRow === 0){
- Ext.fly(rows[0]).addClass(this.firstRowCls);
- }
- Ext.fly(rows[rows.length - 1]).addClass(this.lastRowCls);
- },
- afterRender : function(){
- if(!this.ds || !this.cm){
- return;
- }
- this.mainBody.dom.innerHTML = this.renderRows() || ' ';
- this.processRows(0, true);
- if(this.deferEmptyText !== true){
- this.applyEmptyText();
- }
- this.grid.fireEvent('viewready', this.grid);
- },
- renderUI : function(){
- var header = this.renderHeaders();
- var body = this.templates.body.apply({rows:' '});
- var html = this.templates.master.apply({
- body: body,
- header: header,
- ostyle: 'width:'+this.getOffsetWidth()+';',
- bstyle: 'width:'+this.getTotalWidth()+';'
- });
- var g = this.grid;
- g.getGridEl().dom.innerHTML = html;
- this.initElements();
- Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
- this.mainHd.on({
- scope: this,
- mouseover: this.handleHdOver,
- mouseout: this.handleHdOut,
- mousemove: this.handleHdMove
- });
- this.scroller.on('scroll', this.syncScroll, this);
- if(g.enableColumnResize !== false){
- this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
- }
- if(g.enableColumnMove){
- this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
- this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
- }
- if(g.enableHdMenu !== false){
- this.hmenu = new Ext.menu.Menu({id: g.id + '-hctx'});
- this.hmenu.add(
- {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
- {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
- );
- if(g.enableColumnHide !== false){
- this.colMenu = new Ext.menu.Menu({id:g.id + '-hcols-menu'});
- this.colMenu.on({
- scope: this,
- beforeshow: this.beforeColMenuShow,
- itemclick: this.handleHdMenuClick
- });
- this.hmenu.add('-', {
- itemId:'columns',
- hideOnClick: false,
- text: this.columnsText,
- menu: this.colMenu,
- iconCls: 'x-cols-icon'
- });
- }
- this.hmenu.on('itemclick', this.handleHdMenuClick, this);
- }
- if(g.trackMouseOver){
- this.mainBody.on({
- scope: this,
- mouseover: this.onRowOver,
- mouseout: this.onRowOut
- });
- }
- if(g.enableDragDrop || g.enableDrag){
- this.dragZone = new Ext.grid.GridDragZone(g, {
- ddGroup : g.ddGroup || 'GridDD'
- });
- }
- this.updateHeaderSortState();
- },
- processEvent: Ext.emptyFn,
- layout : function(){
- if(!this.mainBody){
- return;
- }
- var g = this.grid;
- var c = g.getGridEl();
- var csize = c.getSize(true);
- var vw = csize.width;
- if(!g.hideHeaders && (vw < 20 || csize.height < 20)){
- return;
- }
- if(g.autoHeight){
- this.scroller.dom.style.overflow = 'visible';
- if(Ext.isWebKit){
- this.scroller.dom.style.position = 'static';
- }
- }else{
- this.el.setSize(csize.width, csize.height);
- var hdHeight = this.mainHd.getHeight();
- var vh = csize.height - (hdHeight);
- this.scroller.setSize(vw, vh);
- if(this.innerHd){
- this.innerHd.style.width = (vw)+'px';
- }
- }
- if(this.forceFit){
- if(this.lastViewWidth != vw){
- this.fitColumns(false, false);
- this.lastViewWidth = vw;
- }
- }else {
- this.autoExpand();
- this.syncHeaderScroll();
- }
- this.onLayout(vw, vh);
- },
- onLayout : function(vw, vh){
- },
- onColumnWidthUpdated : function(col, w, tw){
- },
- onAllColumnWidthsUpdated : function(ws, tw){
- },
- onColumnHiddenUpdated : function(col, hidden, tw){
- },
- updateColumnText : function(col, text){
- },
- afterMove : function(colIndex){
- },
- init : function(grid){
- this.grid = grid;
- this.initTemplates();
- this.initData(grid.store, grid.colModel);
- this.initUI(grid);
- },
- getColumnId : function(index){
- return this.cm.getColumnId(index);
- },
- getOffsetWidth : function() {
- return (this.cm.getTotalWidth() + this.getScrollOffset()) + 'px';
- },
- getScrollOffset: function(){
- return Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
- },
- renderHeaders : function(){
- var cm = this.cm,
- ts = this.templates,
- ct = ts.hcell,
- cb = [],
- p = {},
- len = cm.getColumnCount(),
- last = len - 1;
- for(var i = 0; i < len; i++){
- p.id = cm.getColumnId(i);
- p.value = cm.getColumnHeader(i) || '';
- p.style = this.getColumnStyle(i, true);
- p.tooltip = this.getColumnTooltip(i);
- p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
- if(cm.config[i].align == 'right'){
- p.istyle = 'padding-right:16px';
- } else {
- delete p.istyle;
- }
- cb[cb.length] = ct.apply(p);
- }
- return ts.header.apply({cells: cb.join(''), tstyle:'width:'+this.getTotalWidth()+';'});
- },
- getColumnTooltip : function(i){
- var tt = this.cm.getColumnTooltip(i);
- if(tt){
- if(Ext.QuickTips.isEnabled()){
- return 'ext:qtip="'+tt+'"';
- }else{
- return 'title="'+tt+'"';
- }
- }
- return '';
- },
- beforeUpdate : function(){
- this.grid.stopEditing(true);
- },
- updateHeaders : function(){
- this.innerHd.firstChild.innerHTML = this.renderHeaders();
- this.innerHd.firstChild.style.width = this.getOffsetWidth();
- this.innerHd.firstChild.firstChild.style.width = this.getTotalWidth();
- },
- focusRow : function(row){
- this.focusCell(row, 0, false);
- },
- focusCell : function(row, col, hscroll){
- this.syncFocusEl(this.ensureVisible(row, col, hscroll));
- if(Ext.isGecko){
- this.focusEl.focus();
- }else{
- this.focusEl.focus.defer(1, this.focusEl);
- }
- },
- resolveCell : function(row, col, hscroll){
- if(!Ext.isNumber(row)){
- row = row.rowIndex;
- }
- if(!this.ds){
- return null;
- }
- if(row < 0 || row >= this.ds.getCount()){
- return null;
- }
- col = (col !== undefined ? col : 0);
- var rowEl = this.getRow(row),
- cm = this.cm,
- colCount = cm.getColumnCount(),
- cellEl;
- if(!(hscroll === false && col === 0)){
- while(col < colCount && cm.isHidden(col)){
- col++;
- }
- cellEl = this.getCell(row, col);
- }
- return {row: rowEl, cell: cellEl};
- },
- getResolvedXY : function(resolved){
- if(!resolved){
- return null;
- }
- var s = this.scroller.dom, c = resolved.cell, r = resolved.row;
- return c ? Ext.fly(c).getXY() : [this.el.getX(), Ext.fly(r).getY()];
- },
- syncFocusEl : function(row, col, hscroll){
- var xy = row;
- if(!Ext.isArray(xy)){
- row = Math.min(row, Math.max(0, this.getRows().length-1));
- xy = this.getResolvedXY(this.resolveCell(row, col, hscroll));
- }
- this.focusEl.setXY(xy||this.scroller.getXY());
- },
- ensureVisible : function(row, col, hscroll){
- var resolved = this.resolveCell(row, col, hscroll);
- if(!resolved || !resolved.row){
- return;
- }
- var rowEl = resolved.row,
- cellEl = resolved.cell,
- c = this.scroller.dom,
- ctop = 0,
- p = rowEl,
- stop = this.el.dom;
- while(p && p != stop){
- ctop += p.offsetTop;
- p = p.offsetParent;
- }
- ctop -= this.mainHd.dom.offsetHeight;
- stop = parseInt(c.scrollTop, 10);
- var cbot = ctop + rowEl.offsetHeight,
- ch = c.clientHeight,
- sbot = stop + ch;
- if(ctop < stop){
- c.scrollTop = ctop;
- }else if(cbot > sbot){
- c.scrollTop = cbot-ch;
- }
- if(hscroll !== false){
- var cleft = parseInt(cellEl.offsetLeft, 10);
- var cright = cleft + cellEl.offsetWidth;
- var sleft = parseInt(c.scrollLeft, 10);
- var sright = sleft + c.clientWidth;
- if(cleft < sleft){
- c.scrollLeft = cleft;
- }else if(cright > sright){
- c.scrollLeft = cright-c.clientWidth;
- }
- }
- return this.getResolvedXY(resolved);
- },
- insertRows : function(dm, firstRow, lastRow, isUpdate){
- var last = dm.getCount() - 1;
- if(!isUpdate && firstRow === 0 && lastRow >= last){
- this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
- this.refresh();
- this.fireEvent('rowsinserted', this, firstRow, lastRow);
- }else{
- if(!isUpdate){
- this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
- }
- var html = this.renderRows(firstRow, lastRow),
- before = this.getRow(firstRow);
- if(before){
- if(firstRow === 0){
- Ext.fly(this.getRow(0)).removeClass(this.firstRowCls);
- }
- Ext.DomHelper.insertHtml('beforeBegin', before, html);
- }else{
- var r = this.getRow(last - 1);
- if(r){
- Ext.fly(r).removeClass(this.lastRowCls);
- }
- Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
- }
- if(!isUpdate){
- this.fireEvent('rowsinserted', this, firstRow, lastRow);
- this.processRows(firstRow);
- }else if(firstRow === 0 || firstRow >= last){
- Ext.fly(this.getRow(firstRow)).addClass(firstRow === 0 ? this.firstRowCls : this.lastRowCls);
- }
- }
- this.syncFocusEl(firstRow);
- },
- deleteRows : function(dm, firstRow, lastRow){
- if(dm.getRowCount()<1){
- this.refresh();
- }else{
- this.fireEvent('beforerowsdeleted', this, firstRow, lastRow);
- this.removeRows(firstRow, lastRow);
- this.processRows(firstRow);
- this.fireEvent('rowsdeleted', this, firstRow, lastRow);
- }
- },
- getColumnStyle : function(col, isHeader){
- var style = !isHeader ? (this.cm.config[col].css || '') : '';
- style += 'width:'+this.getColumnWidth(col)+';';
- if(this.cm.isHidden(col)){
- style += 'display:none;';
- }
- var align = this.cm.config[col].align;
- if(align){
- style += 'text-align:'+align+';';
- }
- return style;
- },
- getColumnWidth : function(col){
- var w = this.cm.getColumnWidth(col);
- if(Ext.isNumber(w)){
- return (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2) ? w : (w - this.borderWidth > 0 ? w - this.borderWidth : 0)) + 'px';
- }
- return w;
- },
- getTotalWidth : function(){
- return this.cm.getTotalWidth()+'px';
- },
- fitColumns : function(preventRefresh, onlyExpand, omitColumn){
- var cm = this.cm, i;
- var tw = cm.getTotalWidth(false);
- var aw = this.grid.getGridEl().getWidth(true)-this.getScrollOffset();
- if(aw < 20){
- return;
- }
- var extra = aw - tw;
- if(extra === 0){
- return false;
- }
- var vc = cm.getColumnCount(true);
- var ac = vc-(Ext.isNumber(omitColumn) ? 1 : 0);
- if(ac === 0){
- ac = 1;
- omitColumn = undefined;
- }
- var colCount = cm.getColumnCount();
- var cols = [];
- var extraCol = 0;
- var width = 0;
- var w;
- for (i = 0; i < colCount; i++){
- if(!cm.isHidden(i) && !cm.isFixed(i) && i !== omitColumn){
- w = cm.getColumnWidth(i);
- cols.push(i);
- extraCol = i;
- cols.push(w);
- width += w;
- }
- }
- var frac = (aw - cm.getTotalWidth())/width;
- while (cols.length){
- w = cols.pop();
- i = cols.pop();
- cm.setColumnWidth(i, Math.max(this.grid.minColumnWidth, Math.floor(w + w*frac)), true);
- }
- if((tw = cm.getTotalWidth(false)) > aw){
- var adjustCol = ac != vc ? omitColumn : extraCol;
- cm.setColumnWidth(adjustCol, Math.max(1,
- cm.getColumnWidth(adjustCol)- (tw-aw)), true);
- }
- if(preventRefresh !== true){
- this.updateAllColumnWidths();
- }
- return true;
- },
- autoExpand : function(preventUpdate){
- var g = this.grid, cm = this.cm;
- if(!this.userResized && g.autoExpandColumn){
- var tw = cm.getTotalWidth(false);
- var aw = this.grid.getGridEl().getWidth(true)-this.getScrollOffset();
- if(tw != aw){
- var ci = cm.getIndexById(g.autoExpandColumn);
- var currentWidth = cm.getColumnWidth(ci);
- var cw = Math.min(Math.max(((aw-tw)+currentWidth), g.autoExpandMin), g.autoExpandMax);
- if(cw != currentWidth){
- cm.setColumnWidth(ci, cw, true);
- if(preventUpdate !== true){
- this.updateColumnWidth(ci, cw);
- }
- }
- }
- }
- },
- getColumnData : function(){
- var cs = [], cm = this.cm, colCount = cm.getColumnCount();
- for(var i = 0; i < colCount; i++){
- var name = cm.getDataIndex(i);
- cs[i] = {
- name : (!Ext.isDefined(name) ? this.ds.fields.get(i).name : name),
- renderer : cm.getRenderer(i),
- scope: cm.getRendererScope(i),
- id : cm.getColumnId(i),
- style : this.getColumnStyle(i)
- };
- }
- return cs;
- },
- renderRows : function(startRow, endRow){
- var g = this.grid, cm = g.colModel, ds = g.store, stripe = g.stripeRows;
- var colCount = cm.getColumnCount();
- if(ds.getCount() < 1){
- return '';
- }
- var cs = this.getColumnData();
- startRow = startRow || 0;
- endRow = !Ext.isDefined(endRow) ? ds.getCount()-1 : endRow;
- var rs = ds.getRange(startRow, endRow);
- return this.doRender(cs, rs, ds, startRow, colCount, stripe);
- },
- renderBody : function(){
- var markup = this.renderRows() || ' ';
- return this.templates.body.apply({rows: markup});
- },
- refreshRow : function(record){
- var ds = this.ds, index;
- if(Ext.isNumber(record)){
- index = record;
- record = ds.getAt(index);
- if(!record){
- return;
- }
- }else{
- index = ds.indexOf(record);
- if(index < 0){
- return;
- }
- }
- this.insertRows(ds, index, index, true);
- this.getRow(index).rowIndex = index;
- this.onRemove(ds, record, index+1, true);
- this.fireEvent('rowupdated', this, index, record);
- },
- refresh : function(headersToo){
- this.fireEvent('beforerefresh', this);
- this.grid.stopEditing(true);
- var result = this.renderBody();
- this.mainBody.update(result).setWidth(this.getTotalWidth());
- if(headersToo === true){
- this.updateHeaders();
- this.updateHeaderSortState();
- }
- this.processRows(0, true);
- this.layout();
- this.applyEmptyText();
- this.fireEvent('refresh', this);
- },
- applyEmptyText : function(){
- if(this.emptyText && !this.hasRows()){
- this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
- }
- },
- updateHeaderSortState : function(){
- var state = this.ds.getSortState();
- if(!state){
- return;
- }
- if(!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)){
- this.grid.fireEvent('sortchange', this.grid, state);
- }
- this.sortState = state;
- var sortColumn = this.cm.findColumnIndex(state.field);
- if(sortColumn != -1){
- var sortDir = state.direction;
- this.updateSortIcon(sortColumn, sortDir);
- }
- },
- clearHeaderSortState : function(){
- if(!this.sortState){
- return;
- }
- this.grid.fireEvent('sortchange', this.grid, null);
- this.mainHd.select('td').removeClass(this.sortClasses);
- delete this.sortState;
- },
- destroy : function(){
- if(this.colMenu){
- Ext.menu.MenuMgr.unregister(this.colMenu);
- this.colMenu.destroy();
- delete this.colMenu;
- }
- if(this.hmenu){
- Ext.menu.MenuMgr.unregister(this.hmenu);
- this.hmenu.destroy();
- delete this.hmenu;
- }
- this.initData(null, null);
- this.purgeListeners();
- Ext.fly(this.innerHd).un("click", this.handleHdDown, this);
- if(this.grid.enableColumnMove){
- Ext.destroy(
- this.columnDrag.el,
- this.columnDrag.proxy.ghost,
- this.columnDrag.proxy.el,
- this.columnDrop.el,
- this.columnDrop.proxyTop,
- this.columnDrop.proxyBottom,
- this.columnDrag.dragData.ddel,
- this.columnDrag.dragData.header
- );
- if (this.columnDrag.proxy.anim) {
- Ext.destroy(this.columnDrag.proxy.anim);
- }
- delete this.columnDrag.proxy.ghost;
- delete this.columnDrag.dragData.ddel;
- delete this.columnDrag.dragData.header;
- this.columnDrag.destroy();
- delete Ext.dd.DDM.locationCache[this.columnDrag.id];
- delete this.columnDrag._domRef;
- delete this.columnDrop.proxyTop;
- delete this.columnDrop.proxyBottom;
- this.columnDrop.destroy();
- delete Ext.dd.DDM.locationCache["gridHeader" + this.grid.getGridEl().id];
- delete this.columnDrop._domRef;
- delete Ext.dd.DDM.ids[this.columnDrop.ddGroup];
- }
- if (this.splitZone){
- this.splitZone.destroy();
- delete this.splitZone._domRef;
- delete Ext.dd.DDM.ids["gridSplitters" + this.grid.getGridEl().id];
- }
- Ext.fly(this.innerHd).removeAllListeners();
- Ext.removeNode(this.innerHd);
- delete this.innerHd;
- Ext.destroy(
- this.el,
- this.mainWrap,
- this.mainHd,
- this.scroller,
- this.mainBody,
- this.focusEl,
- this.resizeMarker,
- this.resizeProxy,
- this.activeHdBtn,
- this.dragZone,
- this.splitZone,
- this._flyweight
- );
- delete this.grid.container;
- if(this.dragZone){
- this.dragZone.destroy();
- }
- Ext.dd.DDM.currentTarget = null;
- delete Ext.dd.DDM.locationCache[this.grid.getGridEl().id];
- Ext.EventManager.removeResizeListener(this.onWindowResize, this);
- },
- onDenyColumnHide : function(){
- },
- render : function(){
- if(this.autoFill){
- var ct = this.grid.ownerCt;
- if (ct && ct.getLayout()){
- ct.on('afterlayout', function(){
- this.fitColumns(true, true);
- this.updateHeaders();
- }, this, {single: true});
- }else{
- this.fitColumns(true, true);
- }
- }else if(this.forceFit){
- this.fitColumns(true, false);
- }else if(this.grid.autoExpandColumn){
- this.autoExpand(true);
- }
- this.renderUI();
- },
- initData : function(ds, cm){
- if(this.ds){
- this.ds.un('load', this.onLoad, this);
- this.ds.un('datachanged', this.onDataChange, this);
- this.ds.un('add', this.onAdd, this);
- this.ds.un('remove', this.onRemove, this);
- this.ds.un('update', this.onUpdate, this);
- this.ds.un('clear', this.onClear, this);
- if(this.ds !== ds && this.ds.autoDestroy){
- this.ds.destroy();
- }
- }
- if(ds){
- ds.on({
- scope: this,
- load: this.onLoad,
- datachanged: this.onDataChange,
- add: this.onAdd,
- remove: this.onRemove,
- update: this.onUpdate,
- clear: this.onClear
- });
- }
- this.ds = ds;
- if(this.cm){
- this.cm.un('configchange', this.onColConfigChange, this);
- this.cm.un('widthchange', this.onColWidthChange, this);
- this.cm.un('headerchange', this.onHeaderChange, this);
- this.cm.un('hiddenchange', this.onHiddenChange, this);
- this.cm.un('columnmoved', this.onColumnMove, this);
- }
- if(cm){
- delete this.lastViewWidth;
- cm.on({
- scope: this,
- configchange: this.onColConfigChange,
- widthchange: this.onColWidthChange,
- headerchange: this.onHeaderChange,
- hiddenchange: this.onHiddenChange,
- columnmoved: this.onColumnMove
- });
- }
- this.cm = cm;
- },
- onDataChange : function(){
- this.refresh();
- this.updateHeaderSortState();
- this.syncFocusEl(0);
- },
- onClear : function(){
- this.refresh();
- this.syncFocusEl(0);
- },
- onUpdate : function(ds, record){
- this.refreshRow(record);
- },
- onAdd : function(ds, records, index){
- this.insertRows(ds, index, index + (records.length-1));
- },
- onRemove : function(ds, record, index, isUpdate){
- if(isUpdate !== true){
- this.fireEvent('beforerowremoved', this, index, record);
- }
- this.removeRow(index);
- if(isUpdate !== true){
- this.processRows(index);
- this.applyEmptyText();
- this.fireEvent('rowremoved', this, index, record);
- }
- },
- onLoad : function(){
- this.scrollToTop.defer(Ext.isGecko ? 1 : 0, this);
- },
- onColWidthChange : function(cm, col, width){
- this.updateColumnWidth(col, width);
- },
- onHeaderChange : function(cm, col, text){
- this.updateHeaders();
- },
- onHiddenChange : function(cm, col, hidden){
- this.updateColumnHidden(col, hidden);
- },
- onColumnMove : function(cm, oldIndex, newIndex){
- this.indexMap = null;
- var s = this.getScrollState();
- this.refresh(true);
- this.restoreScroll(s);
- this.afterMove(newIndex);
- this.grid.fireEvent('columnmove', oldIndex, newIndex);
- },
- onColConfigChange : function(){
- delete this.lastViewWidth;
- this.indexMap = null;
- this.refresh(true);
- },
- initUI : function(grid){
- grid.on('headerclick', this.onHeaderClick, this);
- },
- initEvents : function(){
- },
- onHeaderClick : function(g, index){
- if(this.headersDisabled || !this.cm.isSortable(index)){
- return;
- }
- g.stopEditing(true);
- g.store.sort(this.cm.getDataIndex(index));
- },
- onRowOver : function(e, t){
- var row;
- if((row = this.findRowIndex(t)) !== false){
- this.addRowClass(row, 'x-grid3-row-over');
- }
- },
- onRowOut : function(e, t){
- var row;
- if((row = this.findRowIndex(t)) !== false && !e.within(this.getRow(row), true)){
- this.removeRowClass(row, 'x-grid3-row-over');
- }
- },
- handleWheel : function(e){
- e.stopPropagation();
- },
- onRowSelect : function(row){
- this.addRowClass(row, this.selectedRowClass);
- },
- onRowDeselect : function(row){
- this.removeRowClass(row, this.selectedRowClass);
- },
- onCellSelect : function(row, col){
- var cell = this.getCell(row, col);
- if(cell){
- this.fly(cell).addClass('x-grid3-cell-selected');
- }
- },
- onCellDeselect : function(row, col){
- var cell = this.getCell(row, col);
- if(cell){
- this.fly(cell).removeClass('x-grid3-cell-selected');
- }
- },
- onColumnSplitterMoved : function(i, w){
- this.userResized = true;
- var cm = this.grid.colModel;
- cm.setColumnWidth(i, w, true);
- if(this.forceFit){
- this.fitColumns(true, false, i);
- this.updateAllColumnWidths();
- }else{
- this.updateColumnWidth(i, w);
- this.syncHeaderScroll();
- }
- this.grid.fireEvent('columnresize', i, w);
- },
- handleHdMenuClick : function(item){
- var index = this.hdCtxIndex,
- cm = this.cm,
- ds = this.ds,
- id = item.getItemId();
- switch(id){
- case 'asc':
- ds.sort(cm.getDataIndex(index), 'ASC');
- break;
- case 'desc':
- ds.sort(cm.getDataIndex(index), 'DESC');
- break;
- default:
- index = cm.getIndexById(id.substr(4));
- if(index != -1){
- if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){
- this.onDenyColumnHide();
- return false;
- }
- cm.setHidden(index, item.checked);
- }
- }
- return true;
- },
- isHideableColumn : function(c){
- return !c.hidden && !c.fixed;
- },
- beforeColMenuShow : function(){
- var cm = this.cm, colCount = cm.getColumnCount();
- this.colMenu.removeAll();
- for(var i = 0; i < colCount; i++){
- if(cm.config[i].fixed !== true && cm.config[i].hideable !== false){
- this.colMenu.add(new Ext.menu.CheckItem({
- itemId: 'col-'+cm.getColumnId(i),
- text: cm.getColumnHeader(i),
- checked: !cm.isHidden(i),
- hideOnClick:false,
- disabled: cm.config[i].hideable === false
- }));
- }
- }
- },
- handleHdDown : function(e, t){
- if(Ext.fly(t).hasClass('x-grid3-hd-btn')){
- e.stopEvent();
- var hd = this.findHeaderCell(t);
- Ext.fly(hd).addClass('x-grid3-hd-menu-open');
- var index = this.getCellIndex(hd);
- this.hdCtxIndex = index;
- var ms = this.hmenu.items, cm = this.cm;
- ms.get('asc').setDisabled(!cm.isSortable(index));
- ms.get('desc').setDisabled(!cm.isSortable(index));
- this.hmenu.on('hide', function(){
- Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
- }, this, {single:true});
- this.hmenu.show(t, 'tl-bl?');
- }
- },
- handleHdOver : function(e, t){
- var hd = this.findHeaderCell(t);
- if(hd && !this.headersDisabled){
- this.activeHdRef = t;
- this.activeHdIndex = this.getCellIndex(hd);
- var fly = this.fly(hd);
- this.activeHdRegion = fly.getRegion();
- if(!this.cm.isMenuDisabled(this.activeHdIndex)){
- fly.addClass('x-grid3-hd-over');
- this.activeHdBtn = fly.child('.x-grid3-hd-btn');
- if(this.activeHdBtn){
- this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
- }
- }
- }
- },
- handleHdMove : function(e, t){
- var hd = this.findHeaderCell(this.activeHdRef);
- if(hd && !this.headersDisabled){
- var hw = this.splitHandleWidth || 5,
- r = this.activeHdRegion,
- x = e.getPageX(),
- ss = hd.style,
- cur = '';
- if(this.grid.enableColumnResize !== false){
- if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex-1)){
- cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize';
- }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){
- cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
- }
- }
- ss.cursor = cur;
- }
- },
- handleHdOut : function(e, t){
- var hd = this.findHeaderCell(t);
- if(hd && (!Ext.isIE || !e.within(hd, true))){
- this.activeHdRef = null;
- this.fly(hd).removeClass('x-grid3-hd-over');
- hd.style.cursor = '';
- }
- },
- hasRows : function(){
- var fc = this.mainBody.dom.firstChild;
- return fc && fc.nodeType == 1 && fc.className != 'x-grid-empty';
- },
- bind : function(d, c){
- this.initData(d, c);
- }
- });
- Ext.grid.GridView.SplitDragZone = function(grid, hd){
- this.grid = grid;
- this.view = grid.getView();
- this.marker = this.view.resizeMarker;
- this.proxy = this.view.resizeProxy;
- Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd,
- 'gridSplitters' + this.grid.getGridEl().id, {
- dragElId : Ext.id(this.proxy.dom), resizeFrame:false
- });
- this.scroll = false;
- this.hw = this.view.splitHandleWidth || 5;
- };
- Ext.extend(Ext.grid.GridView.SplitDragZone, Ext.dd.DDProxy, {
- b4StartDrag : function(x, y){
- this.view.headersDisabled = true;
- var h = this.view.mainWrap.getHeight();
- this.marker.setHeight(h);
- this.marker.show();
- this.marker.alignTo(this.view.getHeaderCell(this.cellIndex), 'tl-tl', [-2, 0]);
- this.proxy.setHeight(h);
- var w = this.cm.getColumnWidth(this.cellIndex);
- var minw = Math.max(w-this.grid.minColumnWidth, 0);
- this.resetConstraints();
- this.setXConstraint(minw, 1000);
- this.setYConstraint(0, 0);
- this.minX = x - minw;
- this.maxX = x + 1000;
- this.startPos = x;
- Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
- },
- allowHeaderDrag : function(e){
- return true;
- },
- handleMouseDown : function(e){
- var t = this.view.findHeaderCell(e.getTarget());
- if(t && this.allowHeaderDrag(e)){
- var xy = this.view.fly(t).getXY(), x = xy[0], y = xy[1];
- var exy = e.getXY(), ex = exy[0];
- var w = t.offsetWidth, adjust = false;
- if((ex - x) <= this.hw){
- adjust = -1;
- }else if((x+w) - ex <= this.hw){
- adjust = 0;
- }
- if(adjust !== false){
- this.cm = this.grid.colModel;
- var ci = this.view.getCellIndex(t);
- if(adjust == -1){
- if (ci + adjust < 0) {
- return;
- }
- while(this.cm.isHidden(ci+adjust)){
- --adjust;
- if(ci+adjust < 0){
- return;
- }
- }
- }
- this.cellIndex = ci+adjust;
- this.split = t.dom;
- if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
- Ext.grid.GridView.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
- }
- }else if(this.view.columnDrag){
- this.view.columnDrag.callHandleMouseDown(e);
- }
- }
- },
- endDrag : function(e){
- this.marker.hide();
- var v = this.view;
- var endX = Math.max(this.minX, e.getPageX());
- var diff = endX - this.startPos;
- v.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
- setTimeout(function(){
- v.headersDisabled = false;
- }, 50);
- },
- autoOffset : function(){
- this.setDelta(0,0);
- }
- });
- Ext.grid.HeaderDragZone = Ext.extend(Ext.dd.DragZone, {
- maxDragWidth: 120,
- constructor : function(grid, hd, hd2){
- this.grid = grid;
- this.view = grid.getView();
- this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
- Ext.grid.HeaderDragZone.superclass.constructor.call(this, hd);
- if(hd2){
- this.setHandleElId(Ext.id(hd));
- this.setOuterHandleElId(Ext.id(hd2));
- }
- this.scroll = false;
- },
- getDragData : function(e){
- var t = Ext.lib.Event.getTarget(e);
- var h = this.view.findHeaderCell(t);
- if(h){
- return {ddel: h.firstChild, header:h};
- }
- return false;
- },
- onInitDrag : function(e){
- this.view.headersDisabled = true;
- var clone = this.dragData.ddel.cloneNode(true);
- clone.id = Ext.id();
- clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
- this.proxy.update(clone);
- return true;
- },
- afterValidDrop : function(){
- var v = this.view;
- setTimeout(function(){
- v.headersDisabled = false;
- }, 50);
- },
- afterInvalidDrop : function(){
- var v = this.view;
- setTimeout(function(){
- v.headersDisabled = false;
- }, 50);
- }
- });
- Ext.grid.HeaderDropZone = Ext.extend(Ext.dd.DropZone, {
- proxyOffsets : [-4, -9],
- fly: Ext.Element.fly,
- constructor : function(grid, hd, hd2){
- this.grid = grid;
- this.view = grid.getView();
- this.proxyTop = Ext.DomHelper.append(document.body, {
- cls:"col-move-top", html:" "
- }, true);
- this.proxyBottom = Ext.DomHelper.append(document.body, {
- cls:"col-move-bottom", html:" "
- }, true);
- this.proxyTop.hide = this.proxyBottom.hide = function(){
- this.setLeftTop(-100,-100);
- this.setStyle("visibility", "hidden");
- };
- this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
- Ext.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
- },
- getTargetFromEvent : function(e){
- var t = Ext.lib.Event.getTarget(e);
- var cindex = this.view.findCellIndex(t);
- if(cindex !== false){
- return this.view.getHeaderCell(cindex);
- }
- },
- nextVisible : function(h){
- var v = this.view, cm = this.grid.colModel;
- h = h.nextSibling;
- while(h){
- if(!cm.isHidden(v.getCellIndex(h))){
- return h;
- }
- h = h.nextSibling;
- }
- return null;
- },
- prevVisible : function(h){
- var v = this.view, cm = this.grid.colModel;
- h = h.prevSibling;
- while(h){
- if(!cm.isHidden(v.getCellIndex(h))){
- return h;
- }
- h = h.prevSibling;
- }
- return null;
- },
- positionIndicator : function(h, n, e){
- var x = Ext.lib.Event.getPageX(e);
- var r = Ext.lib.Dom.getRegion(n.firstChild);
- var px, pt, py = r.top + this.proxyOffsets[1];
- if((r.right - x) <= (r.right-r.left)/2){
- px = r.right+this.view.borderWidth;
- pt = "after";
- }else{
- px = r.left;
- pt = "before";
- }
- if(this.grid.colModel.isFixed(this.view.getCellIndex(n))){
- return false;
- }
- px += this.proxyOffsets[0];
- this.proxyTop.setLeftTop(px, py);
- this.proxyTop.show();
- if(!this.bottomOffset){
- this.bottomOffset = this.view.mainHd.getHeight();
- }
- this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
- this.proxyBottom.show();
- return pt;
- },
- onNodeEnter : function(n, dd, e, data){
- if(data.header != n){
- this.positionIndicator(data.header, n, e);
- }
- },
- onNodeOver : function(n, dd, e, data){
- var result = false;
- if(data.header != n){
- result = this.positionIndicator(data.header, n, e);
- }
- if(!result){
- this.proxyTop.hide();
- this.proxyBottom.hide();
- }
- return result ? this.dropAllowed : this.dropNotAllowed;
- },
- onNodeOut : function(n, dd, e, data){
- this.proxyTop.hide();
- this.proxyBottom.hide();
- },
- onNodeDrop : function(n, dd, e, data){
- var h = data.header;
- if(h != n){
- var cm = this.grid.colModel;
- var x = Ext.lib.Event.getPageX(e);
- var r = Ext.lib.Dom.getRegion(n.firstChild);
- var pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before";
- var oldIndex = this.view.getCellIndex(h);
- var newIndex = this.view.getCellIndex(n);
- if(pt == "after"){
- newIndex++;
- }
- if(oldIndex < newIndex){
- newIndex--;
- }
- cm.moveColumn(oldIndex, newIndex);
- return true;
- }
- return false;
- }
- });
- Ext.grid.GridView.ColumnDragZone = Ext.extend(Ext.grid.HeaderDragZone, {
- constructor : function(grid, hd){
- Ext.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
- this.proxy.el.addClass('x-grid3-col-dd');
- },
- handleMouseDown : function(e){
- },
- callHandleMouseDown : function(e){
- Ext.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
- }
- });
- Ext.grid.SplitDragZone = Ext.extend(Ext.dd.DDProxy, {
- fly: Ext.Element.fly,
- constructor : function(grid, hd, hd2){
- this.grid = grid;
- this.view = grid.getView();
- this.proxy = this.view.resizeProxy;
- Ext.grid.SplitDragZone.superclass.constructor.call(this, hd,
- "gridSplitters" + this.grid.getGridEl().id, {
- dragElId : Ext.id(this.proxy.dom), resizeFrame:false
- });
- this.setHandleElId(Ext.id(hd));
- this.setOuterHandleElId(Ext.id(hd2));
- this.scroll = false;
- },
- b4StartDrag : function(x, y){
- this.view.headersDisabled = true;
- this.proxy.setHeight(this.view.mainWrap.getHeight());
- var w = this.cm.getColumnWidth(this.cellIndex);
- var minw = Math.max(w-this.grid.minColumnWidth, 0);
- this.resetConstraints();
- this.setXConstraint(minw, 1000);
- this.setYConstraint(0, 0);
- this.minX = x - minw;
- this.maxX = x + 1000;
- this.startPos = x;
- Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
- },
- handleMouseDown : function(e){
- var ev = Ext.EventObject.setEvent(e);
- var t = this.fly(ev.getTarget());
- if(t.hasClass("x-grid-split")){
- this.cellIndex = this.view.getCellIndex(t.dom);
- this.split = t.dom;
- this.cm = this.grid.colModel;
- if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
- Ext.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
- }
- }
- },
- endDrag : function(e){
- this.view.headersDisabled = false;
- var endX = Math.max(this.minX, Ext.lib.Event.getPageX(e));
- var diff = endX - this.startPos;
- this.view.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
- },
- autoOffset : function(){
- this.setDelta(0,0);
- }
- });
- Ext.grid.GridDragZone = function(grid, config){
- this.view = grid.getView();
- Ext.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config);
- this.scroll = false;
- this.grid = grid;
- this.ddel = document.createElement('div');
- this.ddel.className = 'x-grid-dd-wrap';
- };
- Ext.extend(Ext.grid.GridDragZone, Ext.dd.DragZone, {
- ddGroup : "GridDD",
- getDragData : function(e){
- var t = Ext.lib.Event.getTarget(e);
- var rowIndex = this.view.findRowIndex(t);
- if(rowIndex !== false){
- var sm = this.grid.selModel;
- if(!sm.isSelected(rowIndex) || e.hasModifier()){
- sm.handleMouseDown(this.grid, rowIndex, e);
- }
- return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections:sm.getSelections()};
- }
- return false;
- },
- onInitDrag : function(e){
- var data = this.dragData;
- this.ddel.innerHTML = this.grid.getDragDropText();
- this.proxy.update(this.ddel);
- },
- afterRepair : function(){
- this.dragging = false;
- },
- getRepairXY : function(e, data){
- return false;
- },
- onEndDrag : function(data, e){
- },
- onValidDrop : function(dd, e, id){
- this.hideProxy();
- },
- beforeInvalidDrop : function(e, id){
- }
- });
- Ext.grid.ColumnModel = Ext.extend(Ext.util.Observable, {
- defaultWidth: 100,
- defaultSortable: false,
- constructor : function(config){
- if(config.columns){
- Ext.apply(this, config);
- this.setConfig(config.columns, true);
- }else{
- this.setConfig(config, true);
- }
- this.addEvents(
- "widthchange",
- "headerchange",
- "hiddenchange",
- "columnmoved",
- "configchange"
- );
- Ext.grid.ColumnModel.superclass.constructor.call(this);
- },
- getColumnId : function(index){
- return this.config[index].id;
- },
- getColumnAt : function(index){
- return this.config[index];
- },
- setConfig : function(config, initial){
- var i, c, len;
- if(!initial){
- delete this.totalWidth;
- for(i = 0, len = this.config.length; i < len; i++){
- c = this.config[i];
- if(c.editor){
- c.editor.destroy();
- }
- }
- }
- this.defaults = Ext.apply({
- width: this.defaultWidth,
- sortable: this.defaultSortable
- }, this.defaults);
- this.config = config;
- this.lookup = {};
- for(i = 0, len = config.length; i < len; i++){
- c = Ext.applyIf(config[i], this.defaults);
- if(typeof c.id == 'undefined'){
- c.id = i;
- }
- if(!c.isColumn){
- var Cls = Ext.grid.Column.types[c.xtype || 'gridcolumn'];
- c = new Cls(c);
- config[i] = c;
- }
- this.lookup[c.id] = c;
- }
- if(!initial){
- this.fireEvent('configchange', this);
- }
- },
- getColumnById : function(id){
- return this.lookup[id];
- },
- getIndexById : function(id){
- for(var i = 0, len = this.config.length; i < len; i++){
- if(this.config[i].id == id){
- return i;
- }
- }
- return -1;
- },
- moveColumn : function(oldIndex, newIndex){
- var c = this.config[oldIndex];
- this.config.splice(oldIndex, 1);
- this.config.splice(newIndex, 0, c);
- this.dataMap = null;
- this.fireEvent("columnmoved", this, oldIndex, newIndex);
- },
- getColumnCount : function(visibleOnly){
- if(visibleOnly === true){
- var c = 0;
- for(var i = 0, len = this.config.length; i < len; i++){
- if(!this.isHidden(i)){
- c++;
- }
- }
- return c;
- }
- return this.config.length;
- },
- getColumnsBy : function(fn, scope){
- var r = [];
- for(var i = 0, len = this.config.length; i < len; i++){
- var c = this.config[i];
- if(fn.call(scope||this, c, i) === true){
- r[r.length] = c;
- }
- }
- return r;
- },
- isSortable : function(col){
- return !!this.config[col].sortable;
- },
- isMenuDisabled : function(col){
- return !!this.config[col].menuDisabled;
- },
- getRenderer : function(col){
- if(!this.config[col].renderer){
- return Ext.grid.ColumnModel.defaultRenderer;
- }
- return this.config[col].renderer;
- },
- getRendererScope : function(col){
- return this.config[col].scope;
- },
- setRenderer : function(col, fn){
- this.config[col].renderer = fn;
- },
- getColumnWidth : function(col){
- return this.config[col].width;
- },
- setColumnWidth : function(col, width, suppressEvent){
- this.config[col].width = width;
- this.totalWidth = null;
- if(!suppressEvent){
- this.fireEvent("widthchange", this, col, width);
- }
- },
- getTotalWidth : function(includeHidden){
- if(!this.totalWidth){
- this.totalWidth = 0;
- for(var i = 0, len = this.config.length; i < len; i++){
- if(includeHidden || !this.isHidden(i)){
- this.totalWidth += this.getColumnWidth(i);
- }
- }
- }
- return this.totalWidth;
- },
- getColumnHeader : function(col){
- return this.config[col].header;
- },
- setColumnHeader : function(col, header){
- this.config[col].header = header;
- this.fireEvent("headerchange", this, col, header);
- },
- getColumnTooltip : function(col){
- return this.config[col].tooltip;
- },
- setColumnTooltip : function(col, tooltip){
- this.config[col].tooltip = tooltip;
- },
- getDataIndex : function(col){
- return this.config[col].dataIndex;
- },
- setDataIndex : function(col, dataIndex){
- this.config[col].dataIndex = dataIndex;
- },
- findColumnIndex : function(dataIndex){
- var c = this.config;
- for(var i = 0, len = c.length; i < len; i++){
- if(c[i].dataIndex == dataIndex){
- return i;
- }
- }
- return -1;
- },
- isCellEditable : function(colIndex, rowIndex){
- return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
- },
- getCellEditor : function(colIndex, rowIndex){
- return this.config[colIndex].getCellEditor(rowIndex);
- },
- setEditable : function(col, editable){
- this.config[col].editable = editable;
- },
- isHidden : function(colIndex){
- return !!this.config[colIndex].hidden;
- },
- isFixed : function(colIndex){
- return !!this.config[colIndex].fixed;
- },
- isResizable : function(colIndex){
- return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
- },
- setHidden : function(colIndex, hidden){
- var c = this.config[colIndex];
- if(c.hidden !== hidden){
- c.hidden = hidden;
- this.totalWidth = null;
- this.fireEvent("hiddenchange", this, colIndex, hidden);
- }
- },
- setEditor : function(col, editor){
- Ext.destroy(this.config[col].editor);
- this.config[col].editor = editor;
- },
- destroy : function(){
- for(var i = 0, c = this.config, len = c.length; i < len; i++){
- Ext.destroy(c[i].editor);
- }
- this.purgeListeners();
- }
- });
- Ext.grid.ColumnModel.defaultRenderer = function(value){
- if(typeof value == "string" && value.length < 1){
- return " ";
- }
- return value;
- };
- Ext.grid.AbstractSelectionModel = Ext.extend(Ext.util.Observable, {
- constructor : function(){
- this.locked = false;
- Ext.grid.AbstractSelectionModel.superclass.constructor.call(this);
- },
- init : function(grid){
- this.grid = grid;
- this.initEvents();
- },
- lock : function(){
- this.locked = true;
- },
- unlock : function(){
- this.locked = false;
- },
- isLocked : function(){
- return this.locked;
- },
- destroy: function(){
- this.purgeListeners();
- }
- });
- Ext.grid.RowSelectionModel = Ext.extend(Ext.grid.AbstractSelectionModel, {
- singleSelect : false,
- constructor : function(config){
- Ext.apply(this, config);
- this.selections = new Ext.util.MixedCollection(false, function(o){
- return o.id;
- });
- this.last = false;
- this.lastActive = false;
- this.addEvents(
- 'selectionchange',
- 'beforerowselect',
- 'rowselect',
- 'rowdeselect'
- );
- Ext.grid.RowSelectionModel.superclass.constructor.call(this);
- },
- initEvents : function(){
- if(!this.grid.enableDragDrop && !this.grid.enableDrag){
- this.grid.on('rowmousedown', this.handleMouseDown, this);
- }
- this.rowNav = new Ext.KeyNav(this.grid.getGridEl(), {
- 'up' : function(e){
- if(!e.shiftKey || this.singleSelect){
- this.selectPrevious(false);
- }else if(this.last !== false && this.lastActive !== false){
- var last = this.last;
- this.selectRange(this.last, this.lastActive-1);
- this.grid.getView().focusRow(this.lastActive);
- if(last !== false){
- this.last = last;
- }
- }else{
- this.selectFirstRow();
- }
- },
- 'down' : function(e){
- if(!e.shiftKey || this.singleSelect){
- this.selectNext(false);
- }else if(this.last !== false && this.lastActive !== false){
- var last = this.last;
- this.selectRange(this.last, this.lastActive+1);
- this.grid.getView().focusRow(this.lastActive);
- if(last !== false){
- this.last = last;
- }
- }else{
- this.selectFirstRow();
- }
- },
- scope: this
- });
- this.grid.getView().on({
- scope: this,
- refresh: this.onRefresh,
- rowupdated: this.onRowUpdated,
- rowremoved: this.onRemove
- });
- },
- onRefresh : function(){
- var ds = this.grid.store, index;
- var s = this.getSelections();
- this.clearSelections(true);
- for(var i = 0, len = s.length; i < len; i++){
- var r = s[i];
- if((index = ds.indexOfId(r.id)) != -1){
- this.selectRow(index, true);
- }
- }
- if(s.length != this.selections.getCount()){
- this.fireEvent('selectionchange', this);
- }
- },
- onRemove : function(v, index, r){
- if(this.selections.remove(r) !== false){
- this.fireEvent('selectionchange', this);
- }
- },
- onRowUpdated : function(v, index, r){
- if(this.isSelected(r)){
- v.onRowSelect(index);
- }
- },
- selectRecords : function(records, keepExisting){
- if(!keepExisting){
- this.clearSelections();
- }
- var ds = this.grid.store;
- for(var i = 0, len = records.length; i < len; i++){
- this.selectRow(ds.indexOf(records[i]), true);
- }
- },
- getCount : function(){
- return this.selections.length;
- },
- selectFirstRow : function(){
- this.selectRow(0);
- },
- selectLastRow : function(keepExisting){
- this.selectRow(this.grid.store.getCount() - 1, keepExisting);
- },
- selectNext : function(keepExisting){
- if(this.hasNext()){
- this.selectRow(this.last+1, keepExisting);
- this.grid.getView().focusRow(this.last);
- return true;
- }
- return false;
- },
- selectPrevious : function(keepExisting){
- if(this.hasPrevious()){
- this.selectRow(this.last-1, keepExisting);
- this.grid.getView().focusRow(this.last);
- return true;
- }
- return false;
- },
- hasNext : function(){
- return this.last !== false && (this.last+1) < this.grid.store.getCount();
- },
- hasPrevious : function(){
- return !!this.last;
- },
- getSelections : function(){
- return [].concat(this.selections.items);
- },
- getSelected : function(){
- return this.selections.itemAt(0);
- },
- each : function(fn, scope){
- var s = this.getSelections();
- for(var i = 0, len = s.length; i < len; i++){
- if(fn.call(scope || this, s[i], i) === false){
- return false;
- }
- }
- return true;
- },
- clearSelections : function(fast){
- if(this.isLocked()){
- return;
- }
- if(fast !== true){
- var ds = this.grid.store;
- var s = this.selections;
- s.each(function(r){
- this.deselectRow(ds.indexOfId(r.id));
- }, this);
- s.clear();
- }else{
- this.selections.clear();
- }
- this.last = false;
- },
- selectAll : function(){
- if(this.isLocked()){
- return;
- }
- this.selections.clear();
- for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
- this.selectRow(i, true);
- }
- },
- hasSelection : function(){
- return this.selections.length > 0;
- },
- isSelected : function(index){
- var r = Ext.isNumber(index) ? this.grid.store.getAt(index) : index;
- return (r && this.selections.key(r.id) ? true : false);
- },
- isIdSelected : function(id){
- return (this.selections.key(id) ? true : false);
- },
- handleMouseDown : function(g, rowIndex, e){
- if(e.button !== 0 || this.isLocked()){
- return;
- }
- var view = this.grid.getView();
- if(e.shiftKey && !this.singleSelect && this.last !== false){
- var last = this.last;
- this.selectRange(last, rowIndex, e.ctrlKey);
- this.last = last;
- view.focusRow(rowIndex);
- }else{
- var isSelected = this.isSelected(rowIndex);
- if(e.ctrlKey && isSelected){
- this.deselectRow(rowIndex);
- }else if(!isSelected || this.getCount() > 1){
- this.selectRow(rowIndex, e.ctrlKey || e.shiftKey);
- view.focusRow(rowIndex);
- }
- }
- },
- selectRows : function(rows, keepExisting){
- if(!keepExisting){
- this.clearSelections();
- }
- for(var i = 0, len = rows.length; i < len; i++){
- this.selectRow(rows[i], true);
- }
- },
- selectRange : function(startRow, endRow, keepExisting){
- var i;
- if(this.isLocked()){
- return;
- }
- if(!keepExisting){
- this.clearSelections();
- }
- if(startRow <= endRow){
- for(i = startRow; i <= endRow; i++){
- this.selectRow(i, true);
- }
- }else{
- for(i = startRow; i >= endRow; i--){
- this.selectRow(i, true);
- }
- }
- },
- deselectRange : function(startRow, endRow, preventViewNotify){
- if(this.isLocked()){
- return;
- }
- for(var i = startRow; i <= endRow; i++){
- this.deselectRow(i, preventViewNotify);
- }
- },
- selectRow : function(index, keepExisting, preventViewNotify){
- if(this.isLocked() || (index < 0 || index >= this.grid.store.getCount()) || (keepExisting && this.isSelected(index))){
- return;
- }
- var r = this.grid.store.getAt(index);
- if(r && this.fireEvent('beforerowselect', this, index, keepExisting, r) !== false){
- if(!keepExisting || this.singleSelect){
- this.clearSelections();
- }
- this.selections.add(r);
- this.last = this.lastActive = index;
- if(!preventViewNotify){
- this.grid.getView().onRowSelect(index);
- }
- this.fireEvent('rowselect', this, index, r);
- this.fireEvent('selectionchange', this);
- }
- },
- deselectRow : function(index, preventViewNotify){
- if(this.isLocked()){
- return;
- }
- if(this.last == index){
- this.last = false;
- }
- if(this.lastActive == index){
- this.lastActive = false;
- }
- var r = this.grid.store.getAt(index);
- if(r){
- this.selections.remove(r);
- if(!preventViewNotify){
- this.grid.getView().onRowDeselect(index);
- }
- this.fireEvent('rowdeselect', this, index, r);
- this.fireEvent('selectionchange', this);
- }
- },
- restoreLast : function(){
- if(this._last){
- this.last = this._last;
- }
- },
- acceptsNav : function(row, col, cm){
- return !cm.isHidden(col) && cm.isCellEditable(col, row);
- },
- onEditorKey : function(field, e){
- var k = e.getKey(),
- newCell,
- g = this.grid,
- last = g.lastEdit,
- ed = g.activeEditor,
- ae, last, r, c;
- var shift = e.shiftKey;
- if(k == e.TAB){
- e.stopEvent();
- ed.completeEdit();
- if(shift){
- newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
- }else{
- newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
- }
- }else if(k == e.ENTER){
- if(this.moveEditorOnEnter !== false){
- if(shift){
- newCell = g.walkCells(last.row - 1, last.col, -1, this.acceptsNav, this);
- }else{
- newCell = g.walkCells(last.row + 1, last.col, 1, this.acceptsNav, this);
- }
- }
- }
- if(newCell){
- r = newCell[0];
- c = newCell[1];
- if(last.row != r){
- this.selectRow(r);
- }
- if(g.isEditor && g.editing){
- ae = g.activeEditor;
- if(ae && ae.field.triggerBlur){
- ae.field.triggerBlur();
- }
- }
- g.startEditing(r, c);
- }
- },
- destroy : function(){
- if(this.rowNav){
- this.rowNav.disable();
- this.rowNav = null;
- }
- Ext.grid.RowSelectionModel.superclass.destroy.call(this);
- }
- });
- Ext.grid.Column = Ext.extend(Object, {
- isColumn : true,
- constructor : function(config){
- Ext.apply(this, config);
- if(Ext.isString(this.renderer)){
- this.renderer = Ext.util.Format[this.renderer];
- }else if(Ext.isObject(this.renderer)){
- this.scope = this.renderer.scope;
- this.renderer = this.renderer.fn;
- }
- if(!this.scope){
- this.scope = this;
- }
- if(this.editor){
- this.editor = Ext.create(this.editor, 'textfield');
- }
- },
- renderer : function(value){
- if(Ext.isString(value) && value.length < 1){
- return ' ';
- }
- return value;
- },
- getEditor: function(rowIndex){
- return this.editable !== false ? this.editor : null;
- },
- getCellEditor: function(rowIndex){
- var editor = this.getEditor(rowIndex);
- if(editor){
- if(!editor.startEdit){
- if(!editor.gridEditor){
- editor.gridEditor = new Ext.grid.GridEditor(editor);
- }
- return editor.gridEditor;
- }else if(editor.startEdit){
- return editor;
- }
- }
- return null;
- }
- });
- Ext.grid.BooleanColumn = Ext.extend(Ext.grid.Column, {
- trueText: 'true',
- falseText: 'false',
- undefinedText: ' ',
- constructor: function(cfg){
- Ext.grid.BooleanColumn.superclass.constructor.call(this, cfg);
- var t = this.trueText, f = this.falseText, u = this.undefinedText;
- this.renderer = function(v){
- if(v === undefined){
- return u;
- }
- if(!v || v === 'false'){
- return f;
- }
- return t;
- };
- }
- });
- Ext.grid.NumberColumn = Ext.extend(Ext.grid.Column, {
- format : '0,000.00',
- constructor: function(cfg){
- Ext.grid.NumberColumn.superclass.constructor.call(this, cfg);
- this.renderer = Ext.util.Format.numberRenderer(this.format);
- }
- });
- Ext.grid.DateColumn = Ext.extend(Ext.grid.Column, {
- format : 'm/d/Y',
- constructor: function(cfg){
- Ext.grid.DateColumn.superclass.constructor.call(this, cfg);
- this.renderer = Ext.util.Format.dateRenderer(this.format);
- }
- });
- Ext.grid.TemplateColumn = Ext.extend(Ext.grid.Column, {
- constructor: function(cfg){
- Ext.grid.TemplateColumn.superclass.constructor.call(this, cfg);
- var tpl = (!Ext.isPrimitive(this.tpl) && this.tpl.compile) ? this.tpl : new Ext.XTemplate(this.tpl);
- this.renderer = function(value, p, r){
- return tpl.apply(r.data);
- };
- this.tpl = tpl;
- }
- });
- Ext.grid.Column.types = {
- gridcolumn : Ext.grid.Column,
- booleancolumn: Ext.grid.BooleanColumn,
- numbercolumn: Ext.grid.NumberColumn,
- datecolumn: Ext.grid.DateColumn,
- templatecolumn: Ext.grid.TemplateColumn
- };
- Ext.grid.RowNumberer = Ext.extend(Object, {
- header: "",
- width: 23,
- sortable: false,
- constructor : function(config){
- Ext.apply(this, config);
- if(this.rowspan){
- this.renderer = this.renderer.createDelegate(this);
- }
- },
- fixed:true,
- menuDisabled:true,
- dataIndex: '',
- id: 'numberer',
- rowspan: undefined,
- renderer : function(v, p, record, rowIndex){
- if(this.rowspan){
- p.cellAttr = 'rowspan="'+this.rowspan+'"';
- }
- return rowIndex+1;
- }
- });
- Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
- header : '<div class="x-grid3-hd-checker"> </div>',
- width : 20,
- sortable : false,
- menuDisabled : true,
- fixed : true,
- dataIndex : '',
- id : 'checker',
- constructor : function(){
- Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments);
- if(this.checkOnly){
- this.handleMouseDown = Ext.emptyFn;
- }
- },
- initEvents : function(){
- Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);
- this.grid.on('render', function(){
- var view = this.grid.getView();
- view.mainBody.on('mousedown', this.onMouseDown, this);
- Ext.fly(view.innerHd).on('mousedown', this.onHdMouseDown, this);
- }, this);
- },
- onMouseDown : function(e, t){
- if(e.button === 0 && t.className == 'x-grid3-row-checker'){
- e.stopEvent();
- var row = e.getTarget('.x-grid3-row');
- if(row){
- var index = row.rowIndex;
- if(this.isSelected(index)){
- this.deselectRow(index);
- }else{
- this.selectRow(index, true);
- }
- }
- }
- },
- onHdMouseDown : function(e, t){
- if(t.className == 'x-grid3-hd-checker'){
- e.stopEvent();
- var hd = Ext.fly(t.parentNode);
- var isChecked = hd.hasClass('x-grid3-hd-checker-on');
- if(isChecked){
- hd.removeClass('x-grid3-hd-checker-on');
- this.clearSelections();
- }else{
- hd.addClass('x-grid3-hd-checker-on');
- this.selectAll();
- }
- }
- },
- renderer : function(v, p, record){
- return '<div class="x-grid3-row-checker"> </div>';
- }
- });
- Ext.grid.CellSelectionModel = Ext.extend(Ext.grid.AbstractSelectionModel, {
- constructor : function(config){
- Ext.apply(this, config);
- this.selection = null;
- this.addEvents(
- "beforecellselect",
- "cellselect",
- "selectionchange"
- );
- Ext.grid.CellSelectionModel.superclass.constructor.call(this);
- },
- initEvents : function(){
- this.grid.on('cellmousedown', this.handleMouseDown, this);
- this.grid.on(Ext.EventManager.useKeydown ? 'keydown' : 'keypress', this.handleKeyDown, this);
- this.grid.getView().on({
- scope: this,
- refresh: this.onViewChange,
- rowupdated: this.onRowUpdated,
- beforerowremoved: this.clearSelections,
- beforerowsinserted: this.clearSelections
- });
- if(this.grid.isEditor){
- this.grid.on('beforeedit', this.beforeEdit, this);
- }
- },
- beforeEdit : function(e){
- this.select(e.row, e.column, false, true, e.record);
- },
- onRowUpdated : function(v, index, r){
- if(this.selection && this.selection.record == r){
- v.onCellSelect(index, this.selection.cell[1]);
- }
- },
- onViewChange : function(){
- this.clearSelections(true);
- },
- getSelectedCell : function(){
- return this.selection ? this.selection.cell : null;
- },
- clearSelections : function(preventNotify){
- var s = this.selection;
- if(s){
- if(preventNotify !== true){
- this.grid.view.onCellDeselect(s.cell[0], s.cell[1]);
- }
- this.selection = null;
- this.fireEvent("selectionchange", this, null);
- }
- },
- hasSelection : function(){
- return this.selection ? true : false;
- },
- handleMouseDown : function(g, row, cell, e){
- if(e.button !== 0 || this.isLocked()){
- return;
- }
- this.select(row, cell);
- },
- select : function(rowIndex, colIndex, preventViewNotify, preventFocus, r){
- if(this.fireEvent("beforecellselect", this, rowIndex, colIndex) !== false){
- this.clearSelections();
- r = r || this.grid.store.getAt(rowIndex);
- this.selection = {
- record : r,
- cell : [rowIndex, colIndex]
- };
- if(!preventViewNotify){
- var v = this.grid.getView();
- v.onCellSelect(rowIndex, colIndex);
- if(preventFocus !== true){
- v.focusCell(rowIndex, colIndex);
- }
- }
- this.fireEvent("cellselect", this, rowIndex, colIndex);
- this.fireEvent("selectionchange", this, this.selection);
- }
- },
- isSelectable : function(rowIndex, colIndex, cm){
- return !cm.isHidden(colIndex);
- },
- onEditorKey: function(field, e){
- if(e.getKey() == e.TAB){
- this.handleKeyDown(e);
- }
- },
- handleKeyDown : function(e){
- if(!e.isNavKeyPress()){
- return;
- }
- var k = e.getKey(),
- g = this.grid,
- s = this.selection,
- sm = this,
- walk = function(row, col, step){
- return g.walkCells(
- row,
- col,
- step,
- g.isEditor && g.editing ? sm.acceptsNav : sm.isSelectable,
- sm
- );
- },
- cell, newCell, r, c, ae;
- switch(k){
- case e.ESC:
- case e.PAGE_UP:
- case e.PAGE_DOWN:
- break;
- default:
- e.stopEvent();
- break;
- }
- if(!s){
- cell = walk(0, 0, 1);
- if(cell){
- this.select(cell[0], cell[1]);
- }
- return;
- }
- cell = s.cell;
- r = cell[0];
- c = cell[1];
- switch(k){
- case e.TAB:
- if(e.shiftKey){
- newCell = walk(r, c - 1, -1);
- }else{
- newCell = walk(r, c + 1, 1);
- }
- break;
- case e.DOWN:
- newCell = walk(r + 1, c, 1);
- break;
- case e.UP:
- newCell = walk(r - 1, c, -1);
- break;
- case e.RIGHT:
- newCell = walk(r, c + 1, 1);
- break;
- case e.LEFT:
- newCell = walk(r, c - 1, -1);
- break;
- case e.ENTER:
- if (g.isEditor && !g.editing) {
- g.startEditing(r, c);
- return;
- }
- break;
- }
- if(newCell){
- r = newCell[0];
- c = newCell[1];
- this.select(r, c);
- if(g.isEditor && g.editing){
- ae = g.activeEditor;
- if(ae && ae.field.triggerBlur){
- ae.field.triggerBlur();
- }
- g.startEditing(r, c);
- }
- }
- },
- acceptsNav : function(row, col, cm){
- return !cm.isHidden(col) && cm.isCellEditable(col, row);
- }
- });
- Ext.grid.EditorGridPanel = Ext.extend(Ext.grid.GridPanel, {
- clicksToEdit: 2,
- forceValidation: false,
- isEditor : true,
- detectEdit: false,
- autoEncode : false,
- trackMouseOver: false,
- initComponent : function(){
- Ext.grid.EditorGridPanel.superclass.initComponent.call(this);
- if(!this.selModel){
- this.selModel = new Ext.grid.CellSelectionModel();
- }
- this.activeEditor = null;
- this.addEvents(
- "beforeedit",
- "afteredit",
- "validateedit"
- );
- },
- initEvents : function(){
- Ext.grid.EditorGridPanel.superclass.initEvents.call(this);
- this.getGridEl().on('mousewheel', this.stopEditing.createDelegate(this, [true]), this);
- this.on('columnresize', this.stopEditing, this, [true]);
- if(this.clicksToEdit == 1){
- this.on("cellclick", this.onCellDblClick, this);
- }else {
- var view = this.getView();
- if(this.clicksToEdit == 'auto' && view.mainBody){
- view.mainBody.on('mousedown', this.onAutoEditClick, this);
- }
- this.on('celldblclick', this.onCellDblClick, this);
- }
- },
- onResize : function(){
- Ext.grid.EditorGridPanel.superclass.onResize.apply(this, arguments);
- var ae = this.activeEditor;
- if(this.editing && ae){
- ae.realign(true);
- }
- },
- onCellDblClick : function(g, row, col){
- this.startEditing(row, col);
- },
- onAutoEditClick : function(e, t){
- if(e.button !== 0){
- return;
- }
- var row = this.view.findRowIndex(t),
- col = this.view.findCellIndex(t);
- if(row !== false && col !== false){
- this.stopEditing();
- if(this.selModel.getSelectedCell){
- var sc = this.selModel.getSelectedCell();
- if(sc && sc[0] === row && sc[1] === col){
- this.startEditing(row, col);
- }
- }else{
- if(this.selModel.isSelected(row)){
- this.startEditing(row, col);
- }
- }
- }
- },
- onEditComplete : function(ed, value, startValue){
- this.editing = false;
- this.activeEditor = null;
- var r = ed.record,
- field = this.colModel.getDataIndex(ed.col);
- value = this.postEditValue(value, startValue, r, field);
- if(this.forceValidation === true || String(value) !== String(startValue)){
- var e = {
- grid: this,
- record: r,
- field: field,
- originalValue: startValue,
- value: value,
- row: ed.row,
- column: ed.col,
- cancel:false
- };
- if(this.fireEvent("validateedit", e) !== false && !e.cancel && String(value) !== String(startValue)){
- r.set(field, e.value);
- delete e.cancel;
- this.fireEvent("afteredit", e);
- }
- }
- this.view.focusCell(ed.row, ed.col);
- },
- startEditing : function(row, col){
- this.stopEditing();
- if(this.colModel.isCellEditable(col, row)){
- this.view.ensureVisible(row, col, true);
- var r = this.store.getAt(row),
- field = this.colModel.getDataIndex(col),
- e = {
- grid: this,
- record: r,
- field: field,
- value: r.data[field],
- row: row,
- column: col,
- cancel:false
- };
- if(this.fireEvent("beforeedit", e) !== false && !e.cancel){
- this.editing = true;
- var ed = this.colModel.getCellEditor(col, row);
- if(!ed){
- return;
- }
- if(!ed.rendered){
- ed.parentEl = this.view.getEditorParent(ed);
- ed.on({
- scope: this,
- render: {
- fn: function(c){
- c.field.focus(false, true);
- },
- single: true,
- scope: this
- },
- specialkey: function(field, e){
- this.getSelectionModel().onEditorKey(field, e);
- },
- complete: this.onEditComplete,
- canceledit: this.stopEditing.createDelegate(this, [true])
- });
- }
- Ext.apply(ed, {
- row : row,
- col : col,
- record : r
- });
- this.lastEdit = {
- row: row,
- col: col
- };
- this.activeEditor = ed;
- var v = this.preEditValue(r, field);
- ed.startEdit(this.view.getCell(row, col).firstChild, Ext.isDefined(v) ? v : '');
- }
- }
- },
- preEditValue : function(r, field){
- var value = r.data[field];
- return this.autoEncode && Ext.isString(value) ? Ext.util.Format.htmlDecode(value) : value;
- },
- postEditValue : function(value, originalValue, r, field){
- return this.autoEncode && Ext.isString(value) ? Ext.util.Format.htmlEncode(value) : value;
- },
- stopEditing : function(cancel){
- if(this.editing){
- var ae = this.activeEditor;
- if(ae){
- ae[cancel === true ? 'cancelEdit' : 'completeEdit']();
- this.view.focusCell(ae.row, ae.col);
- }
- this.activeEditor = null;
- }
- this.editing = false;
- }
- });
- Ext.reg('editorgrid', Ext.grid.EditorGridPanel);
- Ext.grid.GridEditor = function(field, config){
- Ext.grid.GridEditor.superclass.constructor.call(this, field, config);
- field.monitorTab = false;
- };
- Ext.extend(Ext.grid.GridEditor, Ext.Editor, {
- alignment: "tl-tl",
- autoSize: "width",
- hideEl : false,
- cls: "x-small-editor x-grid-editor",
- shim:false,
- shadow:false
- });
- Ext.grid.PropertyRecord = Ext.data.Record.create([
- {name:'name',type:'string'}, 'value'
- ]);
- Ext.grid.PropertyStore = Ext.extend(Ext.util.Observable, {
- constructor : function(grid, source){
- this.grid = grid;
- this.store = new Ext.data.Store({
- recordType : Ext.grid.PropertyRecord
- });
- this.store.on('update', this.onUpdate, this);
- if(source){
- this.setSource(source);
- }
- Ext.grid.PropertyStore.superclass.constructor.call(this);
- },
- setSource : function(o){
- this.source = o;
- this.store.removeAll();
- var data = [];
- for(var k in o){
- if(this.isEditableValue(o[k])){
- data.push(new Ext.grid.PropertyRecord({name: k, value: o[k]}, k));
- }
- }
- this.store.loadRecords({records: data}, {}, true);
- },
- onUpdate : function(ds, record, type){
- if(type == Ext.data.Record.EDIT){
- var v = record.data.value;
- var oldValue = record.modified.value;
- if(this.grid.fireEvent('beforepropertychange', this.source, record.id, v, oldValue) !== false){
- this.source[record.id] = v;
- record.commit();
- this.grid.fireEvent('propertychange', this.source, record.id, v, oldValue);
- }else{
- record.reject();
- }
- }
- },
- getProperty : function(row){
- return this.store.getAt(row);
- },
- isEditableValue: function(val){
- return Ext.isPrimitive(val) || Ext.isDate(val);
- },
- setValue : function(prop, value){
- this.source[prop] = value;
- this.store.getById(prop).set('value', value);
- },
- getSource : function(){
- return this.source;
- }
- });
- Ext.grid.PropertyColumnModel = Ext.extend(Ext.grid.ColumnModel, {
- nameText : 'Name',
- valueText : 'Value',
- dateFormat : 'm/j/Y',
- constructor : function(grid, store){
- var g = Ext.grid,
- f = Ext.form;
- this.grid = grid;
- g.PropertyColumnModel.superclass.constructor.call(this, [
- {header: this.nameText, width:50, sortable: true, dataIndex:'name', id: 'name', menuDisabled:true},
- {header: this.valueText, width:50, resizable:false, dataIndex: 'value', id: 'value', menuDisabled:true}
- ]);
- this.store = store;
- var bfield = new f.Field({
- autoCreate: {tag: 'select', children: [
- {tag: 'option', value: 'true', html: 'true'},
- {tag: 'option', value: 'false', html: 'false'}
- ]},
- getValue : function(){
- return this.el.dom.value == 'true';
- }
- });
- this.editors = {
- 'date' : new g.GridEditor(new f.DateField({selectOnFocus:true})),
- 'string' : new g.GridEditor(new f.TextField({selectOnFocus:true})),
- 'number' : new g.GridEditor(new f.NumberField({selectOnFocus:true, style:'text-align:left;'})),
- 'boolean' : new g.GridEditor(bfield, {
- autoSize: 'both'
- })
- };
- this.renderCellDelegate = this.renderCell.createDelegate(this);
- this.renderPropDelegate = this.renderProp.createDelegate(this);
- },
- renderDate : function(dateVal){
- return dateVal.dateFormat(this.dateFormat);
- },
- renderBool : function(bVal){
- return bVal ? 'true' : 'false';
- },
- isCellEditable : function(colIndex, rowIndex){
- return colIndex == 1;
- },
- getRenderer : function(col){
- return col == 1 ?
- this.renderCellDelegate : this.renderPropDelegate;
- },
- renderProp : function(v){
- return this.getPropertyName(v);
- },
- renderCell : function(val){
- var rv = val;
- if(Ext.isDate(val)){
- rv = this.renderDate(val);
- }else if(typeof val == 'boolean'){
- rv = this.renderBool(val);
- }
- return Ext.util.Format.htmlEncode(rv);
- },
- getPropertyName : function(name){
- var pn = this.grid.propertyNames;
- return pn && pn[name] ? pn[name] : name;
- },
- getCellEditor : function(colIndex, rowIndex){
- var p = this.store.getProperty(rowIndex),
- n = p.data.name,
- val = p.data.value;
- if(this.grid.customEditors[n]){
- return this.grid.customEditors[n];
- }
- if(Ext.isDate(val)){
- return this.editors.date;
- }else if(typeof val == 'number'){
- return this.editors.number;
- }else if(typeof val == 'boolean'){
- return this.editors['boolean'];
- }else{
- return this.editors.string;
- }
- },
- destroy : function(){
- Ext.grid.PropertyColumnModel.superclass.destroy.call(this);
- for(var ed in this.editors){
- Ext.destroy(this.editors[ed]);
- }
- }
- });
- Ext.grid.PropertyGrid = Ext.extend(Ext.grid.EditorGridPanel, {
- enableColumnMove:false,
- stripeRows:false,
- trackMouseOver: false,
- clicksToEdit:1,
- enableHdMenu : false,
- viewConfig : {
- forceFit:true
- },
- initComponent : function(){
- this.customEditors = this.customEditors || {};
- this.lastEditRow = null;
- var store = new Ext.grid.PropertyStore(this);
- this.propStore = store;
- var cm = new Ext.grid.PropertyColumnModel(this, store);
- store.store.sort('name', 'ASC');
- this.addEvents(
- 'beforepropertychange',
- 'propertychange'
- );
- this.cm = cm;
- this.ds = store.store;
- Ext.grid.PropertyGrid.superclass.initComponent.call(this);
- this.mon(this.selModel, 'beforecellselect', function(sm, rowIndex, colIndex){
- if(colIndex === 0){
- this.startEditing.defer(200, this, [rowIndex, 1]);
- return false;
- }
- }, this);
- },
- onRender : function(){
- Ext.grid.PropertyGrid.superclass.onRender.apply(this, arguments);
- this.getGridEl().addClass('x-props-grid');
- },
- afterRender: function(){
- Ext.grid.PropertyGrid.superclass.afterRender.apply(this, arguments);
- if(this.source){
- this.setSource(this.source);
- }
- },
- setSource : function(source){
- this.propStore.setSource(source);
- },
- getSource : function(){
- return this.propStore.getSource();
- }
- });
- Ext.reg("propertygrid", Ext.grid.PropertyGrid);
- Ext.grid.GroupingView = Ext.extend(Ext.grid.GridView, {
- groupByText : 'Group By This Field',
- showGroupsText : 'Show in Groups',
- hideGroupedColumn : false,
- showGroupName : true,
- startCollapsed : false,
- enableGrouping : true,
- enableGroupingMenu : true,
- enableNoGroups : true,
- emptyGroupText : '(None)',
- ignoreAdd : false,
- groupTextTpl : '{text}',
- groupMode: 'value',
- gidSeed : 1000,
- initTemplates : function(){
- Ext.grid.GroupingView.superclass.initTemplates.call(this);
- this.state = {};
- var sm = this.grid.getSelectionModel();
- sm.on(sm.selectRow ? 'beforerowselect' : 'beforecellselect',
- this.onBeforeRowSelect, this);
- if(!this.startGroup){
- this.startGroup = new Ext.XTemplate(
- '<div id="{groupId}" class="x-grid-group {cls}">',
- '<div id="{groupId}-hd" class="x-grid-group-hd" style="{style}"><div class="x-grid-group-title">', this.groupTextTpl ,'</div></div>',
- '<div id="{groupId}-bd" class="x-grid-group-body">'
- );
- }
- this.startGroup.compile();
- if(!this.endGroup){
- this.endGroup = '</div></div>';
- }
- this.endGroup = '</div></div>';
- },
- findGroup : function(el){
- return Ext.fly(el).up('.x-grid-group', this.mainBody.dom);
- },
- getGroups : function(){
- return this.hasRows() ? this.mainBody.dom.childNodes : [];
- },
- onAdd : function(){
- if(this.enableGrouping && !this.ignoreAdd){
- var ss = this.getScrollState();
- this.refresh();
- this.restoreScroll(ss);
- }else if(!this.enableGrouping){
- Ext.grid.GroupingView.superclass.onAdd.apply(this, arguments);
- }
- },
- onRemove : function(ds, record, index, isUpdate){
- Ext.grid.GroupingView.superclass.onRemove.apply(this, arguments);
- var g = document.getElementById(record._groupId);
- if(g && g.childNodes[1].childNodes.length < 1){
- Ext.removeNode(g);
- }
- this.applyEmptyText();
- },
- refreshRow : function(record){
- if(this.ds.getCount()==1){
- this.refresh();
- }else{
- this.isUpdating = true;
- Ext.grid.GroupingView.superclass.refreshRow.apply(this, arguments);
- this.isUpdating = false;
- }
- },
- beforeMenuShow : function(){
- var item, items = this.hmenu.items, disabled = this.cm.config[this.hdCtxIndex].groupable === false;
- if((item = items.get('groupBy'))){
- item.setDisabled(disabled);
- }
- if((item = items.get('showGroups'))){
- item.setDisabled(disabled);
- item.setChecked(this.enableGrouping, true);
- }
- },
- renderUI : function(){
- Ext.grid.GroupingView.superclass.renderUI.call(this);
- this.mainBody.on('mousedown', this.interceptMouse, this);
- if(this.enableGroupingMenu && this.hmenu){
- this.hmenu.add('-',{
- itemId:'groupBy',
- text: this.groupByText,
- handler: this.onGroupByClick,
- scope: this,
- iconCls:'x-group-by-icon'
- });
- if(this.enableNoGroups){
- this.hmenu.add({
- itemId:'showGroups',
- text: this.showGroupsText,
- checked: true,
- checkHandler: this.onShowGroupsClick,
- scope: this
- });
- }
- this.hmenu.on('beforeshow', this.beforeMenuShow, this);
- }
- },
- processEvent: function(name, e){
- var hd = e.getTarget('.x-grid-group-hd', this.mainBody);
- if(hd){
- var field = this.getGroupField(),
- prefix = this.getPrefix(field),
- groupValue = hd.id.substring(prefix.length);
- groupValue = groupValue.substr(0, groupValue.length - 3);
- if(groupValue){
- this.grid.fireEvent('group' + name, this.grid, field, groupValue, e);
- }
- }
- },
- onGroupByClick : function(){
- this.enableGrouping = true;
- this.grid.store.groupBy(this.cm.getDataIndex(this.hdCtxIndex));
- this.beforeMenuShow();
- this.refresh();
- },
- onShowGroupsClick : function(mi, checked){
- this.enableGrouping = checked;
- if(checked){
- this.onGroupByClick();
- }else{
- this.grid.store.clearGrouping();
- }
- },
- toggleRowIndex : function(rowIndex, expanded){
- if(!this.enableGrouping){
- return;
- }
- var row = this.getRow(rowIndex);
- if(row){
- this.toggleGroup(this.findGroup(row), expanded);
- }
- },
- toggleGroup : function(group, expanded){
- var gel = Ext.get(group);
- expanded = Ext.isDefined(expanded) ? expanded : gel.hasClass('x-grid-group-collapsed');
- if(this.state[gel.id] !== expanded){
- this.grid.stopEditing(true);
- this.state[gel.id] = expanded;
- gel[expanded ? 'removeClass' : 'addClass']('x-grid-group-collapsed');
- }
- },
- toggleAllGroups : function(expanded){
- var groups = this.getGroups();
- for(var i = 0, len = groups.length; i < len; i++){
- this.toggleGroup(groups[i], expanded);
- }
- },
- expandAllGroups : function(){
- this.toggleAllGroups(true);
- },
- collapseAllGroups : function(){
- this.toggleAllGroups(false);
- },
- interceptMouse : function(e){
- var hd = e.getTarget('.x-grid-group-hd', this.mainBody);
- if(hd){
- e.stopEvent();
- this.toggleGroup(hd.parentNode);
- }
- },
- getGroup : function(v, r, groupRenderer, rowIndex, colIndex, ds){
- var g = groupRenderer ? groupRenderer(v, {}, r, rowIndex, colIndex, ds) : String(v);
- if(g === '' || g === ' '){
- g = this.cm.config[colIndex].emptyGroupText || this.emptyGroupText;
- }
- return g;
- },
- getGroupField : function(){
- return this.grid.store.getGroupState();
- },
- afterRender : function(){
- Ext.grid.GroupingView.superclass.afterRender.call(this);
- if(this.grid.deferRowRender){
- this.updateGroupWidths();
- }
- },
- renderRows : function(){
- var groupField = this.getGroupField();
- var eg = !!groupField;
- if(this.hideGroupedColumn) {
- var colIndex = this.cm.findColumnIndex(groupField),
- hasLastGroupField = Ext.isDefined(this.lastGroupField);
- if(!eg && hasLastGroupField){
- this.mainBody.update('');
- this.cm.setHidden(this.cm.findColumnIndex(this.lastGroupField), false);
- delete this.lastGroupField;
- }else if (eg && !hasLastGroupField){
- this.lastGroupField = groupField;
- this.cm.setHidden(colIndex, true);
- }else if (eg && hasLastGroupField && groupField !== this.lastGroupField) {
- this.mainBody.update('');
- var oldIndex = this.cm.findColumnIndex(this.lastGroupField);
- this.cm.setHidden(oldIndex, false);
- this.lastGroupField = groupField;
- this.cm.setHidden(colIndex, true);
- }
- }
- return Ext.grid.GroupingView.superclass.renderRows.apply(
- this, arguments);
- },
- doRender : function(cs, rs, ds, startRow, colCount, stripe){
- if(rs.length < 1){
- return '';
- }
- var groupField = this.getGroupField(),
- colIndex = this.cm.findColumnIndex(groupField),
- g;
- this.enableGrouping = (this.enableGrouping === false) ? false : !!groupField;
- if(!this.enableGrouping || this.isUpdating){
- return Ext.grid.GroupingView.superclass.doRender.apply(
- this, arguments);
- }
- var gstyle = 'width:' + this.getTotalWidth() + ';',
- cfg = this.cm.config[colIndex],
- groupRenderer = cfg.groupRenderer || cfg.renderer,
- prefix = this.showGroupName ? (cfg.groupName || cfg.header)+': ' : '',
- groups = [],
- curGroup, i, len, gid;
- for(i = 0, len = rs.length; i < len; i++){
- var rowIndex = startRow + i,
- r = rs[i],
- gvalue = r.data[groupField];
- g = this.getGroup(gvalue, r, groupRenderer, rowIndex, colIndex, ds);
- if(!curGroup || curGroup.group != g){
- gid = this.constructId(gvalue, groupField, colIndex);
- this.state[gid] = !(Ext.isDefined(this.state[gid]) ? !this.state[gid] : this.startCollapsed);
- curGroup = {
- group: g,
- gvalue: gvalue,
- text: prefix + g,
- groupId: gid,
- startRow: rowIndex,
- rs: [r],
- cls: this.state[gid] ? '' : 'x-grid-group-collapsed',
- style: gstyle
- };
- groups.push(curGroup);
- }else{
- curGroup.rs.push(r);
- }
- r._groupId = gid;
- }
- var buf = [];
- for(i = 0, len = groups.length; i < len; i++){
- g = groups[i];
- this.doGroupStart(buf, g, cs, ds, colCount);
- buf[buf.length] = Ext.grid.GroupingView.superclass.doRender.call(
- this, cs, g.rs, ds, g.startRow, colCount, stripe);
- this.doGroupEnd(buf, g, cs, ds, colCount);
- }
- return buf.join('');
- },
- getGroupId : function(value){
- var field = this.getGroupField();
- return this.constructId(value, field, this.cm.findColumnIndex(field));
- },
- constructId : function(value, field, idx){
- var cfg = this.cm.config[idx],
- groupRenderer = cfg.groupRenderer || cfg.renderer,
- val = (this.groupMode == 'value') ? value : this.getGroup(value, {data:{}}, groupRenderer, 0, idx, this.ds);
- return this.getPrefix(field) + Ext.util.Format.htmlEncode(val);
- },
- getPrefix: function(field){
- return this.grid.getGridEl().id + '-gp-' + field + '-';
- },
- doGroupStart : function(buf, g, cs, ds, colCount){
- buf[buf.length] = this.startGroup.apply(g);
- },
- doGroupEnd : function(buf, g, cs, ds, colCount){
- buf[buf.length] = this.endGroup;
- },
- getRows : function(){
- if(!this.enableGrouping){
- return Ext.grid.GroupingView.superclass.getRows.call(this);
- }
- var r = [];
- var g, gs = this.getGroups();
- for(var i = 0, len = gs.length; i < len; i++){
- g = gs[i].childNodes[1].childNodes;
- for(var j = 0, jlen = g.length; j < jlen; j++){
- r[r.length] = g[j];
- }
- }
- return r;
- },
- updateGroupWidths : function(){
- if(!this.enableGrouping || !this.hasRows()){
- return;
- }
- var tw = Math.max(this.cm.getTotalWidth(), this.el.dom.offsetWidth-this.getScrollOffset()) +'px';
- var gs = this.getGroups();
- for(var i = 0, len = gs.length; i < len; i++){
- gs[i].firstChild.style.width = tw;
- }
- },
- onColumnWidthUpdated : function(col, w, tw){
- Ext.grid.GroupingView.superclass.onColumnWidthUpdated.call(this, col, w, tw);
- this.updateGroupWidths();
- },
- onAllColumnWidthsUpdated : function(ws, tw){
- Ext.grid.GroupingView.superclass.onAllColumnWidthsUpdated.call(this, ws, tw);
- this.updateGroupWidths();
- },
- onColumnHiddenUpdated : function(col, hidden, tw){
- Ext.grid.GroupingView.superclass.onColumnHiddenUpdated.call(this, col, hidden, tw);
- this.updateGroupWidths();
- },
- onLayout : function(){
- this.updateGroupWidths();
- },
- onBeforeRowSelect : function(sm, rowIndex){
- this.toggleRowIndex(rowIndex, true);
- }
- });
- Ext.grid.GroupingView.GROUP_ID = 1000;