3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
14 <div id="cls-Ext.ListView.Sorter"></div>/**
\r
15 * @class Ext.ListView.Sorter
\r
16 * @extends Ext.util.Observable
\r
17 * <p>Supporting Class for Ext.ListView.</p>
\r
19 * @param {Object} config
\r
21 Ext.ListView.Sorter = Ext.extend(Ext.util.Observable, {
\r
22 <div id="cfg-Ext.ListView.Sorter-sortClasses"></div>/**
\r
23 * @cfg {Array} sortClasses
\r
24 * The CSS classes applied to a header when it is sorted. (defaults to <tt>["sort-asc", "sort-desc"]</tt>)
\r
26 sortClasses : ["sort-asc", "sort-desc"],
\r
28 constructor: function(config){
\r
29 Ext.apply(this, config);
\r
30 Ext.ListView.Sorter.superclass.constructor.call(this);
\r
33 init : function(listView){
\r
34 this.view = listView;
\r
35 listView.on('render', this.initEvents, this);
\r
38 initEvents : function(view){
\r
39 view.mon(view.innerHd, 'click', this.onHdClick, this);
\r
40 view.innerHd.setStyle('cursor', 'pointer');
\r
41 view.mon(view.store, 'datachanged', this.updateSortState, this);
\r
42 this.updateSortState.defer(10, this, [view.store]);
\r
45 updateSortState : function(store){
\r
46 var state = store.getSortState();
\r
50 this.sortState = state;
\r
51 var cs = this.view.columns, sortColumn = -1;
\r
52 for(var i = 0, len = cs.length; i < len; i++){
\r
53 if(cs[i].dataIndex == state.field){
\r
58 if(sortColumn != -1){
\r
59 var sortDir = state.direction;
\r
60 this.updateSortIcon(sortColumn, sortDir);
\r
64 updateSortIcon : function(col, dir){
\r
65 var sc = this.sortClasses;
\r
66 var hds = this.view.innerHd.select('em').removeClass(sc);
\r
67 hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);
\r
70 onHdClick : function(e){
\r
71 var hd = e.getTarget('em', 3);
\r
72 if(hd && !this.view.disableHeaders){
\r
73 var index = this.view.findHeaderIndex(hd);
\r
74 this.view.store.sort(this.view.columns[index].dataIndex);
\r