3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.list.Sorter"></div>/**
\r
10 * @class Ext.list.Sorter
\r
11 * @extends Ext.util.Observable
\r
12 * <p>Supporting Class for Ext.list.ListView</p>
\r
14 * @param {Object} config
\r
16 Ext.list.Sorter = Ext.extend(Ext.util.Observable, {
\r
17 <div id="cfg-Ext.list.Sorter-sortClasses"></div>/**
\r
18 * @cfg {Array} sortClasses
\r
19 * The CSS classes applied to a header when it is sorted. (defaults to <tt>["sort-asc", "sort-desc"]</tt>)
\r
21 sortClasses : ["sort-asc", "sort-desc"],
\r
23 constructor: function(config){
\r
24 Ext.apply(this, config);
\r
25 Ext.list.Sorter.superclass.constructor.call(this);
\r
28 init : function(listView){
\r
29 this.view = listView;
\r
30 listView.on('render', this.initEvents, this);
\r
33 initEvents : function(view){
\r
34 view.mon(view.innerHd, 'click', this.onHdClick, this);
\r
35 view.innerHd.setStyle('cursor', 'pointer');
\r
36 view.mon(view.store, 'datachanged', this.updateSortState, this);
\r
37 this.updateSortState.defer(10, this, [view.store]);
\r
40 updateSortState : function(store){
\r
41 var state = store.getSortState();
\r
45 this.sortState = state;
\r
46 var cs = this.view.columns, sortColumn = -1;
\r
47 for(var i = 0, len = cs.length; i < len; i++){
\r
48 if(cs[i].dataIndex == state.field){
\r
53 if(sortColumn != -1){
\r
54 var sortDir = state.direction;
\r
55 this.updateSortIcon(sortColumn, sortDir);
\r
59 updateSortIcon : function(col, dir){
\r
60 var sc = this.sortClasses;
\r
61 var hds = this.view.innerHd.select('em').removeClass(sc);
\r
62 hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);
\r
65 onHdClick : function(e){
\r
66 var hd = e.getTarget('em', 3);
\r
67 if(hd && !this.view.disableHeaders){
\r
68 var index = this.view.findHeaderIndex(hd);
\r
69 this.view.store.sort(this.view.columns[index].dataIndex);
\r
74 // Backwards compatibility alias
\r
75 Ext.ListView.Sorter = Ext.list.Sorter;</pre>
\r