3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 <div id="cls-Ext.ux.tree.TreeGrid"></div>/**
16 * @class Ext.ux.tree.TreeGrid
17 * @extends Ext.tree.TreePanel
21 Ext.ux.tree.TreeGrid = Ext.extend(Ext.tree.TreePanel, {
25 borderWidth : Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell
30 reserveScrollOffset : true,
33 columnsText : 'Columns',
35 initComponent : function() {
37 this.root = new Ext.tree.AsyncTreeNode({text: 'Root'});
40 // initialize the loader
43 l = new Ext.ux.tree.TreeGridLoader({
44 dataUrl: this.dataUrl,
45 requestMethod: this.requestMethod,
48 }else if(Ext.isObject(l) && !l.load){
49 l = new Ext.ux.tree.TreeGridLoader(l);
53 Ext.ux.tree.TreeGrid.superclass.initComponent.call(this);
58 this.treeGridSorter = new Ext.ux.tree.TreeGridSorter(this, this.enableSort);
61 if(this.columnResize){
62 this.colResizer = new Ext.tree.ColumnResizer(this.columnResize);
63 this.colResizer.init(this);
67 if(!this.internalTpl){
68 this.internalTpl = new Ext.XTemplate(
69 '<div class="x-grid3-header">',
70 '<div class="x-treegrid-header-inner">',
71 '<div class="x-grid3-header-offset">',
72 '<table style="table-layout: fixed;" cellspacing="0" cellpadding="0" border="0"><colgroup><tpl for="columns"><col /></tpl></colgroup>',
73 '<thead><tr class="x-grid3-hd-row">',
74 '<tpl for="columns">',
75 '<td class="x-grid3-hd x-grid3-cell x-treegrid-hd" style="text-align: {align};" id="', this.id, '-xlhd-{#}">',
76 '<div class="x-grid3-hd-inner x-treegrid-hd-inner" unselectable="on">',
77 this.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
78 '{header}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
85 '<div class="x-treegrid-root-node">',
86 '<table class="x-treegrid-root-table" cellpadding="0" cellspacing="0" style="table-layout: fixed;"></table>',
91 if(!this.colgroupTpl) {
92 this.colgroupTpl = new Ext.XTemplate(
93 '<colgroup><tpl for="columns"><col style="width: {width}px"/></tpl></colgroup>'
98 initColumns : function() {
99 var cs = this.columns,
104 for(i = 0; i < len; i++){
107 c.xtype = c.xtype ? (/^tg/.test(c.xtype) ? c.xtype : 'tg' + c.xtype) : 'tgcolumn';
113 if(this.enableSort !== false && c.sortable !== false) {
115 this.enableSort = true;
119 this.columns = columns;
122 onRender : function(){
123 Ext.tree.TreePanel.superclass.onRender.apply(this, arguments);
125 this.el.addClass('x-treegrid');
127 this.outerCt = this.body.createChild({
128 cls:'x-tree-root-ct x-treegrid-ct ' + (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines')
131 this.internalTpl.overwrite(this.outerCt, {columns: this.columns});
133 this.mainHd = Ext.get(this.outerCt.dom.firstChild);
134 this.innerHd = Ext.get(this.mainHd.dom.firstChild);
135 this.innerBody = Ext.get(this.outerCt.dom.lastChild);
136 this.innerCt = Ext.get(this.innerBody.dom.firstChild);
138 this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns});
140 if(this.hideHeaders){
141 this.el.child('.x-grid3-header').setDisplayed('none');
143 else if(this.enableHdMenu !== false){
144 this.hmenu = new Ext.menu.Menu({id: this.id + '-hctx'});
145 if(this.enableColumnHide !== false){
146 this.colMenu = new Ext.menu.Menu({id: this.id + '-hcols-menu'});
149 beforeshow: this.beforeColMenuShow,
150 itemclick: this.handleHdMenuClick
155 text: this.columnsText,
157 iconCls: 'x-cols-icon'
160 this.hmenu.on('itemclick', this.handleHdMenuClick, this);
164 setRootNode : function(node){
165 node.attributes.uiProvider = Ext.ux.tree.TreeGridRootNodeUI;
166 node = Ext.ux.tree.TreeGrid.superclass.setRootNode.call(this, node);
168 this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns});
173 clearInnerCt : function(){
175 var dom = this.innerCt.dom;
176 while(dom.firstChild){
177 dom.removeChild(dom.firstChild);
180 Ext.ux.tree.TreeGrid.superclass.clearInnerCt.call(this);
184 initEvents : function() {
185 Ext.ux.tree.TreeGrid.superclass.initEvents.apply(this, arguments);
187 this.mon(this.innerBody, 'scroll', this.syncScroll, this);
188 this.mon(this.innerHd, 'click', this.handleHdDown, this);
189 this.mon(this.mainHd, {
191 mouseover: this.handleHdOver,
192 mouseout: this.handleHdOut
196 onResize : function(w, h) {
197 Ext.ux.tree.TreeGrid.superclass.onResize.apply(this, arguments);
199 var bd = this.innerBody.dom;
200 var hd = this.innerHd.dom;
207 bd.style.height = this.body.getHeight(true) - hd.offsetHeight + 'px';
211 var sw = Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
212 if(this.reserveScrollOffset || ((bd.offsetWidth - bd.clientWidth) > 10)){
213 this.setScrollOffset(sw);
216 setTimeout(function(){
217 me.setScrollOffset(bd.offsetWidth - bd.clientWidth > 10 ? sw : 0);
223 updateColumnWidths : function() {
224 var cols = this.columns,
225 colCount = cols.length,
226 groups = this.outerCt.query('colgroup'),
227 groupCount = groups.length,
230 for(i = 0; i<colCount; i++) {
232 for(j = 0; j<groupCount; j++) {
234 g.childNodes[i].style.width = (c.hidden ? 0 : c.width) + 'px';
238 for(i = 0, groups = this.innerHd.query('td'), len = groups.length; i<len; i++) {
239 c = Ext.fly(groups[i]);
240 if(cols[i] && cols[i].hidden) {
241 c.addClass('x-treegrid-hd-hidden');
244 c.removeClass('x-treegrid-hd-hidden');
248 var tcw = this.getTotalColumnWidth();
249 Ext.fly(this.innerHd.dom.firstChild).setWidth(tcw + (this.scrollOffset || 0));
250 this.outerCt.select('table').setWidth(tcw);
251 this.syncHeaderScroll();
254 getVisibleColumns : function() {
260 for(i = 0; i<len; i++) {
268 getTotalColumnWidth : function() {
270 for(var i = 0, cs = this.getVisibleColumns(), len = cs.length; i<len; i++) {
271 total += cs[i].width;
276 setScrollOffset : function(scrollOffset) {
277 this.scrollOffset = scrollOffset;
278 this.updateColumnWidths();
282 handleHdDown : function(e, t){
283 var hd = e.getTarget('.x-treegrid-hd');
285 if(hd && Ext.fly(t).hasClass('x-grid3-hd-btn')){
286 var ms = this.hmenu.items,
288 index = this.findHeaderIndex(hd),
293 Ext.fly(hd).addClass('x-grid3-hd-menu-open');
294 this.hdCtxIndex = index;
296 this.fireEvent('headerbuttonclick', ms, c, hd, index);
298 this.hmenu.on('hide', function(){
299 Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
300 }, this, {single:true});
302 this.hmenu.show(t, 'tl-bl?');
305 var index = this.findHeaderIndex(hd);
306 this.fireEvent('headerclick', this.columns[index], hd, index);
311 handleHdOver : function(e, t){
312 var hd = e.getTarget('.x-treegrid-hd');
313 if(hd && !this.headersDisabled){
314 index = this.findHeaderIndex(hd);
315 this.activeHdRef = t;
316 this.activeHdIndex = index;
317 var el = Ext.get(hd);
318 this.activeHdRegion = el.getRegion();
319 el.addClass('x-grid3-hd-over');
320 this.activeHdBtn = el.child('.x-grid3-hd-btn');
321 if(this.activeHdBtn){
322 this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
328 handleHdOut : function(e, t){
329 var hd = e.getTarget('.x-treegrid-hd');
330 if(hd && (!Ext.isIE || !e.within(hd, true))){
331 this.activeHdRef = null;
332 Ext.fly(hd).removeClass('x-grid3-hd-over');
333 hd.style.cursor = '';
337 findHeaderIndex : function(hd){
339 var cs = hd.parentNode.childNodes;
340 for(var i = 0, c; c = cs[i]; i++){
349 beforeColMenuShow : function(){
350 var cols = this.columns,
351 colCount = cols.length,
353 this.colMenu.removeAll();
354 for(i = 1; i < colCount; i++){
356 if(c.hideable !== false){
357 this.colMenu.add(new Ext.menu.CheckItem({
362 disabled: c.hideable === false
369 handleHdMenuClick : function(item){
370 var index = this.hdCtxIndex,
371 id = item.getItemId();
373 if(this.fireEvent('headermenuclick', this.columns[index], id, index) !== false) {
374 index = id.substr(4);
375 if(index > 0 && this.columns[index]) {
376 this.setColumnVisible(index, !item.checked);
383 setColumnVisible : function(index, visible) {
384 this.columns[index].hidden = !visible;
385 this.updateColumnWidths();
388 <div id="method-Ext.ux.tree.TreeGrid-scrollToTop"></div>/**
389 * Scrolls the grid to the top
391 scrollToTop : function(){
392 this.innerBody.dom.scrollTop = 0;
393 this.innerBody.dom.scrollLeft = 0;
397 syncScroll : function(){
398 this.syncHeaderScroll();
399 var mb = this.innerBody.dom;
400 this.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
404 syncHeaderScroll : function(){
405 var mb = this.innerBody.dom;
406 this.innerHd.dom.scrollLeft = mb.scrollLeft;
407 this.innerHd.dom.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
410 registerNode : function(n) {
411 Ext.ux.tree.TreeGrid.superclass.registerNode.call(this, n);
412 if(!n.uiProvider && !n.isRoot && !n.ui.isTreeGridNodeUI) {
413 n.ui = new Ext.ux.tree.TreeGridNodeUI(n);
418 Ext.reg('treegrid', Ext.ux.tree.TreeGrid);</pre>