Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / docs / source / CheckboxSelectionModel.html
1 <html>\r
2 <head>\r
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    \r
4   <title>The source code</title>\r
5     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
6     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
7 </head>\r
8 <body  onload="prettyPrint();">\r
9     <pre class="prettyprint lang-js"><div id="cls-Ext.grid.CheckboxSelectionModel"></div>/**\r
10  * @class Ext.grid.CheckboxSelectionModel\r
11  * @extends Ext.grid.RowSelectionModel\r
12  * A custom selection model that renders a column of checkboxes that can be toggled to select or deselect rows.\r
13  * @constructor\r
14  * @param {Object} config The configuration options\r
15  */\r
16 Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {\r
17 \r
18     <div id="cfg-Ext.grid.CheckboxSelectionModel-checkOnly"></div>/**\r
19      * @cfg {Boolean} checkOnly <tt>true</tt> if rows can only be selected by clicking on the\r
20      * checkbox column (defaults to <tt>false</tt>).\r
21      */\r
22     <div id="cfg-Ext.grid.CheckboxSelectionModel-header"></div>/**\r
23      * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the\r
24      * checkbox column.  Defaults to:<pre><code>\r
25      * '&lt;div class="x-grid3-hd-checker">&#38;#160;&lt;/div>'</tt>\r
26      * </code></pre>\r
27      * The default CSS class of <tt>'x-grid3-hd-checker'</tt> displays a checkbox in the header\r
28      * and provides support for automatic check all/none behavior on header click. This string\r
29      * can be replaced by any valid HTML fragment, including a simple text string (e.g.,\r
30      * <tt>'Select Rows'</tt>), but the automatic check all/none behavior will only work if the\r
31      * <tt>'x-grid3-hd-checker'</tt> class is supplied.\r
32      */\r
33     header : '<div class="x-grid3-hd-checker">&#160;</div>',\r
34     <div id="cfg-Ext.grid.CheckboxSelectionModel-width"></div>/**\r
35      * @cfg {Number} width The default width in pixels of the checkbox column (defaults to <tt>20</tt>).\r
36      */\r
37     width : 20,\r
38     <div id="cfg-Ext.grid.CheckboxSelectionModel-sortable"></div>/**\r
39      * @cfg {Boolean} sortable <tt>true</tt> if the checkbox column is sortable (defaults to\r
40      * <tt>false</tt>).\r
41      */\r
42     sortable : false,\r
43 \r
44     // private\r
45     menuDisabled : true,\r
46     fixed : true,\r
47     dataIndex : '',\r
48     id : 'checker',\r
49 \r
50     constructor : function(){\r
51         Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments);\r
52 \r
53         if(this.checkOnly){\r
54             this.handleMouseDown = Ext.emptyFn;\r
55         }\r
56     },\r
57 \r
58     // private\r
59     initEvents : function(){\r
60         Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);\r
61         this.grid.on('render', function(){\r
62             var view = this.grid.getView();\r
63             view.mainBody.on('mousedown', this.onMouseDown, this);\r
64             Ext.fly(view.innerHd).on('mousedown', this.onHdMouseDown, this);\r
65 \r
66         }, this);\r
67     },\r
68 \r
69     // private\r
70     onMouseDown : function(e, t){\r
71         if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click\r
72             e.stopEvent();\r
73             var row = e.getTarget('.x-grid3-row');\r
74             if(row){\r
75                 var index = row.rowIndex;\r
76                 if(this.isSelected(index)){\r
77                     this.deselectRow(index);\r
78                 }else{\r
79                     this.selectRow(index, true);\r
80                 }\r
81             }\r
82         }\r
83     },\r
84 \r
85     // private\r
86     onHdMouseDown : function(e, t){\r
87         if(t.className == 'x-grid3-hd-checker'){\r
88             e.stopEvent();\r
89             var hd = Ext.fly(t.parentNode);\r
90             var isChecked = hd.hasClass('x-grid3-hd-checker-on');\r
91             if(isChecked){\r
92                 hd.removeClass('x-grid3-hd-checker-on');\r
93                 this.clearSelections();\r
94             }else{\r
95                 hd.addClass('x-grid3-hd-checker-on');\r
96                 this.selectAll();\r
97             }\r
98         }\r
99     },\r
100 \r
101     // private\r
102     renderer : function(v, p, record){\r
103         return '<div class="x-grid3-row-checker">&#160;</div>';\r
104     }\r
105 });</pre>    \r
106 </body>\r
107 </html>