ColumnNodeUI.js
上传用户:shuoshiled
上传日期:2018-01-28
资源大小:10124k
文件大小:4k
源码类别:

中间件编程

开发平台:

JavaScript

  1. /*!  * Ext JS Library 3.0.0  * Copyright(c) 2006-2009 Ext JS, LLC  * licensing@extjs.com  * http://www.extjs.com/license  */ Ext.ns('Ext.ux.tree');
  2. /**
  3.  * @class Ext.ux.tree.ColumnTree
  4.  * @extends Ext.tree.TreePanel
  5.  * 
  6.  * @xtype columntree
  7.  */
  8. Ext.ux.tree.ColumnTree = Ext.extend(Ext.tree.TreePanel, {
  9.     lines : false,
  10.     borderWidth : Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell
  11.     cls : 'x-column-tree',
  12.     onRender : function(){
  13.         Ext.tree.ColumnTree.superclass.onRender.apply(this, arguments);
  14.         this.headers = this.header.createChild({cls:'x-tree-headers'});
  15.         var cols = this.columns, c;
  16.         var totalWidth = 0;
  17.         var scrollOffset = 19; // similar to Ext.grid.GridView default
  18.         for(var i = 0, len = cols.length; i < len; i++){
  19.              c = cols[i];
  20.              totalWidth += c.width;
  21.              this.headers.createChild({
  22.                  cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
  23.                  cn: {
  24.                      cls:'x-tree-hd-text',
  25.                      html: c.header
  26.                  },
  27.                  style:'width:'+(c.width-this.borderWidth)+'px;'
  28.              });
  29.         }
  30.         this.headers.createChild({cls:'x-clear'});
  31.         // prevent floats from wrapping when clipped
  32.         this.headers.setWidth(totalWidth+scrollOffset);
  33.         this.innerCt.setWidth(totalWidth);
  34.     }
  35. });
  36. Ext.reg('columntree', Ext.ux.tree.ColumnTree);
  37. //backwards compat
  38. Ext.tree.ColumnTree = Ext.ux.tree.ColumnTree;
  39. /**
  40.  * @class Ext.ux.tree.ColumnNodeUI
  41.  * @extends Ext.tree.TreeNodeUI
  42.  */
  43. Ext.ux.tree.ColumnNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
  44.     focus: Ext.emptyFn, // prevent odd scrolling behavior
  45.     renderElements : function(n, a, targetNode, bulkRender){
  46.         this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
  47.         var t = n.getOwnerTree();
  48.         var cols = t.columns;
  49.         var bw = t.borderWidth;
  50.         var c = cols[0];
  51.         var buf = [
  52.              '<li class="x-tree-node"><div ext:tree-node-id="',n.id,'" class="x-tree-node-el x-tree-node-leaf ', a.cls,'">',
  53.                 '<div class="x-tree-col" style="width:',c.width-bw,'px;">',
  54.                     '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
  55.                     '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow">',
  56.                     '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on">',
  57.                     '<a hidefocus="on" class="x-tree-node-anchor" href="',a.href ? a.href : "#",'" tabIndex="1" ',
  58.                     a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '>',
  59.                     '<span unselectable="on">', n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]),"</span></a>",
  60.                 "</div>"];
  61.          for(var i = 1, len = cols.length; i < len; i++){
  62.              c = cols[i];
  63.              buf.push('<div class="x-tree-col ',(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
  64.                         '<div class="x-tree-col-text">',(c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]),"</div>",
  65.                       "</div>");
  66.          }
  67.          buf.push(
  68.             '<div class="x-clear"></div></div>',
  69.             '<ul class="x-tree-node-ct" style="display:none;"></ul>',
  70.             "</li>");
  71.         if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
  72.             this.wrap = Ext.DomHelper.insertHtml("beforeBegin",
  73.                                 n.nextSibling.ui.getEl(), buf.join(""));
  74.         }else{
  75.             this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
  76.         }
  77.         this.elNode = this.wrap.childNodes[0];
  78.         this.ctNode = this.wrap.childNodes[1];
  79.         var cs = this.elNode.firstChild.childNodes;
  80.         this.indentNode = cs[0];
  81.         this.ecNode = cs[1];
  82.         this.iconNode = cs[2];
  83.         this.anchor = cs[3];
  84.         this.textNode = cs[3].firstChild;
  85.     }
  86. });
  87. //backwards compat
  88. Ext.tree.ColumnNodeUI = Ext.ux.tree.ColumnNodeUI;