source: trunk/web/addons/job_monarch/lib/extjs-30/src/widgets/grid/CheckboxSelectionModel.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: 3.5 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.grid.CheckboxSelectionModel
9 * @extends Ext.grid.RowSelectionModel
10 * A custom selection model that renders a column of checkboxes that can be toggled to select or deselect rows.
11 * @constructor
12 * @param {Object} config The configuration options
13 */
14Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
15
16    /**
17     * @cfg {Boolean} checkOnly <tt>true</tt> if rows can only be selected by clicking on the
18     * checkbox column (defaults to <tt>false</tt>).
19     */
20    /**
21     * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the
22     * checkbox column.  Defaults to:<pre><code>
23     * '&lt;div class="x-grid3-hd-checker">&#38;#160;&lt;/div>'</tt>
24     * </code></pre>
25     * The default CSS class of <tt>'x-grid3-hd-checker'</tt> displays a checkbox in the header
26     * and provides support for automatic check all/none behavior on header click. This string
27     * can be replaced by any valid HTML fragment, including a simple text string (e.g.,
28     * <tt>'Select Rows'</tt>), but the automatic check all/none behavior will only work if the
29     * <tt>'x-grid3-hd-checker'</tt> class is supplied.
30     */
31    header: '<div class="x-grid3-hd-checker">&#160;</div>',
32    /**
33     * @cfg {Number} width The default width in pixels of the checkbox column (defaults to <tt>20</tt>).
34     */
35    width: 20,
36    /**
37     * @cfg {Boolean} sortable <tt>true</tt> if the checkbox column is sortable (defaults to
38     * <tt>false</tt>).
39     */
40    sortable: false,
41
42    // private
43    menuDisabled:true,
44    fixed:true,
45    dataIndex: '',
46    id: 'checker',
47
48    constructor: function(){
49        Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments);
50
51        if(this.checkOnly){
52            this.handleMouseDown = Ext.emptyFn;
53        }
54    },
55
56    // private
57    initEvents : function(){
58        Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);
59        this.grid.on('render', function(){
60            var view = this.grid.getView();
61            view.mainBody.on('mousedown', this.onMouseDown, this);
62            Ext.fly(view.innerHd).on('mousedown', this.onHdMouseDown, this);
63
64        }, this);
65    },
66
67    // private
68    onMouseDown : function(e, t){
69        if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click
70            e.stopEvent();
71            var row = e.getTarget('.x-grid3-row');
72            if(row){
73                var index = row.rowIndex;
74                if(this.isSelected(index)){
75                    this.deselectRow(index);
76                }else{
77                    this.selectRow(index, true);
78                }
79            }
80        }
81    },
82
83    // private
84    onHdMouseDown : function(e, t){
85        if(t.className == 'x-grid3-hd-checker'){
86            e.stopEvent();
87            var hd = Ext.fly(t.parentNode);
88            var isChecked = hd.hasClass('x-grid3-hd-checker-on');
89            if(isChecked){
90                hd.removeClass('x-grid3-hd-checker-on');
91                this.clearSelections();
92            }else{
93                hd.addClass('x-grid3-hd-checker-on');
94                this.selectAll();
95            }
96        }
97    },
98
99    // private
100    renderer : function(v, p, record){
101        return '<div class="x-grid3-row-checker">&#160;</div>';
102    }
103});
Note: See TracBrowser for help on using the repository browser.