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