source: trunk/web/addons/job_monarch/lib/extjs-30/src/widgets/list/Sorter.js @ 625

Last change on this file since 625 was 625, checked in by ramonb, 15 years ago

lib/extjs-30:

  • new ExtJS 3.0
File size: 2.1 KB
Line 
1/*!
2 * Ext JS Library 3.0.0
3 * Copyright(c) 2006-2009 Ext JS, LLC
4 * licensing@extjs.com
5 * http://www.extjs.com/license
6 */
7/**
8 * @class Ext.ListView.Sorter
9 * @extends Ext.util.Observable
10 * <p>Supporting Class for Ext.ListView.</p>
11 * @constructor
12 * @param {Object} config
13 */
14Ext.ListView.Sorter = Ext.extend(Ext.util.Observable, {
15    /**
16     * @cfg {Array} sortClasses
17     * The CSS classes applied to a header when it is sorted. (defaults to <tt>["sort-asc", "sort-desc"]</tt>)
18     */
19    sortClasses : ["sort-asc", "sort-desc"],
20
21    constructor: function(config){
22        Ext.apply(this, config);
23        Ext.ListView.Sorter.superclass.constructor.call(this);
24    },
25
26    init : function(listView){
27        this.view = listView;
28        listView.on('render', this.initEvents, this);
29    },
30
31    initEvents : function(view){
32        view.mon(view.innerHd, 'click', this.onHdClick, this);
33        view.innerHd.setStyle('cursor', 'pointer');
34        view.mon(view.store, 'datachanged', this.updateSortState, this);
35        this.updateSortState.defer(10, this, [view.store]);
36    },
37
38    updateSortState : function(store){
39        var state = store.getSortState();
40        if(!state){
41            return;
42        }
43        this.sortState = state;
44        var cs = this.view.columns, sortColumn = -1;
45        for(var i = 0, len = cs.length; i < len; i++){
46            if(cs[i].dataIndex == state.field){
47                sortColumn = i;
48                break;
49            }
50        }
51        if(sortColumn != -1){
52            var sortDir = state.direction;
53            this.updateSortIcon(sortColumn, sortDir);
54        }
55    },
56
57    updateSortIcon : function(col, dir){
58        var sc = this.sortClasses;
59        var hds = this.view.innerHd.select('em').removeClass(sc);
60        hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);
61    },
62
63    onHdClick : function(e){
64        var hd = e.getTarget('em', 3);
65        if(hd && !this.view.disableHeaders){
66            var index = this.view.findHeaderIndex(hd);
67            this.view.store.sort(this.view.columns[index].dataIndex);
68        }
69    }
70});
Note: See TracBrowser for help on using the repository browser.