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 Ext.ns('Ext.ux.tree');
17 <div id="cls-Ext.ux.tree.TreeGridSorter"></div>/**
18 * @class Ext.ux.tree.TreeGridSorter
19 * @extends Ext.tree.TreeSorter
20 * Provides sorting of nodes in a {@link Ext.ux.tree.TreeGrid}. The TreeGridSorter automatically monitors events on the
21 * associated TreeGrid that might affect the tree's sort order (beforechildrenrendered, append, insert and textchange).
22 * Example usage:<br />
24 new Ext.ux.tree.TreeGridSorter(myTreeGrid, {
27 sortType: function(node) {
28 // sort by a custom, typed attribute:
29 return parseInt(node.id, 10);
34 * @param {TreeGrid} tree
35 * @param {Object} config
37 Ext.ux.tree.TreeGridSorter = Ext.extend(Ext.tree.TreeSorter, {
38 <div id="cfg-Ext.ux.tree.TreeGridSorter-sortClasses"></div>/**
39 * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>['sort-asc', 'sort-desc']</tt>)
41 sortClasses : ['sort-asc', 'sort-desc'],
42 <div id="cfg-Ext.ux.tree.TreeGridSorter-sortAscText"></div>/**
43 * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to <tt>'Sort Ascending'</tt>)
45 sortAscText : 'Sort Ascending',
46 <div id="cfg-Ext.ux.tree.TreeGridSorter-sortDescText"></div>/**
47 * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to <tt>'Sort Descending'</tt>)
49 sortDescText : 'Sort Descending',
51 constructor : function(tree, config) {
52 if(!Ext.isObject(config)) {
54 property: tree.columns[0].dataIndex || 'text',
59 Ext.ux.tree.TreeGridSorter.superclass.constructor.apply(this, arguments);
62 tree.on('headerclick', this.onHeaderClick, this);
63 tree.ddAppendOnly = true;
66 this.defaultSortFn = function(n1, n2){
68 var desc = me.dir && me.dir.toLowerCase() == 'desc',
69 prop = me.property || 'text',
70 sortType = me.sortType,
71 caseSensitive = me.caseSensitive === true,
72 leafAttr = me.leafAttr || 'leaf',
73 attr1 = n1.attributes,
74 attr2 = n2.attributes;
77 if(attr1[leafAttr] && !attr2[leafAttr]){
80 if(!attr1[leafAttr] && attr2[leafAttr]){
84 var prop1 = attr1[prop],
86 v1 = sortType ? sortType(prop1) : (caseSensitive ? prop1 : prop1.toUpperCase());
87 v2 = sortType ? sortType(prop2) : (caseSensitive ? prop2 : prop2.toUpperCase());
90 return desc ? +1 : -1;
92 return desc ? -1 : +1;
98 tree.on('afterrender', this.onAfterTreeRender, this, {single: true});
99 tree.on('headermenuclick', this.onHeaderMenuClick, this);
102 onAfterTreeRender : function() {
104 this.tree.hmenu.insert(0,
105 {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
106 {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
109 this.updateSortIcon(0, 'asc');
112 onHeaderMenuClick : function(c, id, index) {
113 if(id === 'asc' || id === 'desc') {
114 this.onHeaderClick(c, null, index);
119 onHeaderClick : function(c, el, i) {
120 if(c && !this.tree.headersDisabled){
123 me.property = c.dataIndex;
124 me.dir = c.dir = (c.dir === 'desc' ? 'asc' : 'desc');
125 me.sortType = c.sortType;
126 me.caseSensitive === Ext.isBoolean(c.caseSensitive) ? c.caseSensitive : this.caseSensitive;
127 me.sortFn = c.sortFn || this.defaultSortFn;
129 this.tree.root.cascade(function(n) {
131 me.updateSort(me.tree, n);
135 this.updateSortIcon(i, c.dir);
140 updateSortIcon : function(col, dir){
141 var sc = this.sortClasses,
142 hds = this.tree.innerHd.select('td').removeClass(sc);
143 hds.item(col).addClass(sc[dir == 'desc' ? 1 : 0]);