Upgrade to ExtJS 3.2.2 - Released 06/02/2010
[extjs.git] / docs / source / CheckboxSelectionModel.html
1 <html>
2 <head>
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>
7 </head>
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.
12  * licensing@extjs.com
13  * http://www.extjs.com/license
14  */
15 <div id="cls-Ext.grid.CheckboxSelectionModel"></div>/**
16  * @class Ext.grid.CheckboxSelectionModel
17  * @extends Ext.grid.RowSelectionModel
18  * A custom selection model that renders a column of checkboxes that can be toggled to select or deselect rows.
19  * @constructor
20  * @param {Object} config The configuration options
21  */
22 Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
23
24     <div id="cfg-Ext.grid.CheckboxSelectionModel-checkOnly"></div>/**
25      * @cfg {Boolean} checkOnly <tt>true</tt> if rows can only be selected by clicking on the
26      * checkbox column (defaults to <tt>false</tt>).
27      */
28     <div id="cfg-Ext.grid.CheckboxSelectionModel-header"></div>/**
29      * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the
30      * checkbox column.  Defaults to:<pre><code>
31      * '&lt;div class="x-grid3-hd-checker">&#38;#160;&lt;/div>'</tt>
32      * </code></pre>
33      * The default CSS class of <tt>'x-grid3-hd-checker'</tt> displays a checkbox in the header
34      * and provides support for automatic check all/none behavior on header click. This string
35      * can be replaced by any valid HTML fragment, including a simple text string (e.g.,
36      * <tt>'Select Rows'</tt>), but the automatic check all/none behavior will only work if the
37      * <tt>'x-grid3-hd-checker'</tt> class is supplied.
38      */
39     header : '<div class="x-grid3-hd-checker">&#160;</div>',
40     <div id="cfg-Ext.grid.CheckboxSelectionModel-width"></div>/**
41      * @cfg {Number} width The default width in pixels of the checkbox column (defaults to <tt>20</tt>).
42      */
43     width : 20,
44     <div id="cfg-Ext.grid.CheckboxSelectionModel-sortable"></div>/**
45      * @cfg {Boolean} sortable <tt>true</tt> if the checkbox column is sortable (defaults to
46      * <tt>false</tt>).
47      */
48     sortable : false,
49
50     // private
51     menuDisabled : true,
52     fixed : true,
53     hideable: false,
54     dataIndex : '',
55     id : 'checker',
56
57     constructor : function(){
58         Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments);
59
60         if(this.checkOnly){
61             this.handleMouseDown = Ext.emptyFn;
62         }
63     },
64
65     // private
66     initEvents : function(){
67         Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);
68         this.grid.on('render', function(){
69             var view = this.grid.getView();
70             view.mainBody.on('mousedown', this.onMouseDown, this);
71             Ext.fly(view.innerHd).on('mousedown', this.onHdMouseDown, this);
72
73         }, this);
74     },
75
76     // If handleMouseDown was called from another event (enableDragDrop), set a flag so
77     // onMouseDown does not process it a second time
78     handleMouseDown : function() {
79         Ext.grid.CheckboxSelectionModel.superclass.handleMouseDown.apply(this, arguments);
80         this.mouseHandled = true;
81     },
82
83     // private
84     onMouseDown : function(e, t){
85         if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click
86             e.stopEvent();
87             var row = e.getTarget('.x-grid3-row');
88
89             // mouseHandled flag check for a duplicate selection (handleMouseDown) call
90             if(!this.mouseHandled && row){
91                 var index = row.rowIndex;
92                 if(this.isSelected(index)){
93                     this.deselectRow(index);
94                 }else{
95                     this.selectRow(index, true);
96                     this.grid.getView().focusRow(index);
97                 }
98             }
99         }
100         this.mouseHandled = false;
101     },
102
103     // private
104     onHdMouseDown : function(e, t){
105         if(t.className == 'x-grid3-hd-checker'){
106             e.stopEvent();
107             var hd = Ext.fly(t.parentNode);
108             var isChecked = hd.hasClass('x-grid3-hd-checker-on');
109             if(isChecked){
110                 hd.removeClass('x-grid3-hd-checker-on');
111                 this.clearSelections();
112             }else{
113                 hd.addClass('x-grid3-hd-checker-on');
114                 this.selectAll();
115             }
116         }
117     },
118
119     // private
120     renderer : function(v, p, record){
121         return '<div class="x-grid3-row-checker">&#160;</div>';
122     }
123 });</pre>    
124 </body>
125 </html>