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.2.2
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.list.Sorter"></div>/**
16 * @class Ext.list.Sorter
17 * @extends Ext.util.Observable
18 * <p>Supporting Class for Ext.list.ListView</p>
20 * @param {Object} config
22 Ext.list.Sorter = Ext.extend(Ext.util.Observable, {
23 <div id="cfg-Ext.list.Sorter-sortClasses"></div>/**
24 * @cfg {Array} sortClasses
25 * The CSS classes applied to a header when it is sorted. (defaults to <tt>["sort-asc", "sort-desc"]</tt>)
27 sortClasses : ["sort-asc", "sort-desc"],
29 constructor: function(config){
30 Ext.apply(this, config);
31 Ext.list.Sorter.superclass.constructor.call(this);
34 init : function(listView){
36 listView.on('render', this.initEvents, this);
39 initEvents : function(view){
40 view.mon(view.innerHd, 'click', this.onHdClick, this);
41 view.innerHd.setStyle('cursor', 'pointer');
42 view.mon(view.store, 'datachanged', this.updateSortState, this);
43 this.updateSortState.defer(10, this, [view.store]);
46 updateSortState : function(store){
47 var state = store.getSortState();
51 this.sortState = state;
52 var cs = this.view.columns, sortColumn = -1;
53 for(var i = 0, len = cs.length; i < len; i++){
54 if(cs[i].dataIndex == state.field){
60 var sortDir = state.direction;
61 this.updateSortIcon(sortColumn, sortDir);
65 updateSortIcon : function(col, dir){
66 var sc = this.sortClasses;
67 var hds = this.view.innerHd.select('em').removeClass(sc);
68 hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);
71 onHdClick : function(e){
72 var hd = e.getTarget('em', 3);
73 if(hd && !this.view.disableHeaders){
74 var index = this.view.findHeaderIndex(hd);
75 this.view.store.sort(this.view.columns[index].dataIndex);
80 // Backwards compatibility alias
81 Ext.ListView.Sorter = Ext.list.Sorter;</pre>