3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.grid.CheckboxSelectionModel
\r
9 * @extends Ext.grid.RowSelectionModel
\r
10 * A custom selection model that renders a column of checkboxes that can be toggled to select or deselect rows.
\r
12 * @param {Object} config The configuration options
\r
14 Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
\r
17 * @cfg {Boolean} checkOnly <tt>true</tt> if rows can only be selected by clicking on the
\r
18 * checkbox column (defaults to <tt>false</tt>).
\r
21 * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the
\r
22 * checkbox column. Defaults to:<pre><code>
\r
23 * '<div class="x-grid3-hd-checker">&#160;</div>'</tt>
\r
25 * The default CSS class of <tt>'x-grid3-hd-checker'</tt> displays a checkbox in the header
\r
26 * and provides support for automatic check all/none behavior on header click. This string
\r
27 * can be replaced by any valid HTML fragment, including a simple text string (e.g.,
\r
28 * <tt>'Select Rows'</tt>), but the automatic check all/none behavior will only work if the
\r
29 * <tt>'x-grid3-hd-checker'</tt> class is supplied.
\r
31 header : '<div class="x-grid3-hd-checker"> </div>',
\r
33 * @cfg {Number} width The default width in pixels of the checkbox column (defaults to <tt>20</tt>).
\r
37 * @cfg {Boolean} sortable <tt>true</tt> if the checkbox column is sortable (defaults to
\r
43 menuDisabled : true,
\r
48 constructor : function(){
\r
49 Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments);
\r
52 this.handleMouseDown = Ext.emptyFn;
\r
57 initEvents : function(){
\r
58 Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);
\r
59 this.grid.on('render', function(){
\r
60 var view = this.grid.getView();
\r
61 view.mainBody.on('mousedown', this.onMouseDown, this);
\r
62 Ext.fly(view.innerHd).on('mousedown', this.onHdMouseDown, this);
\r
68 onMouseDown : function(e, t){
\r
69 if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click
\r
71 var row = e.getTarget('.x-grid3-row');
\r
73 var index = row.rowIndex;
\r
74 if(this.isSelected(index)){
\r
75 this.deselectRow(index);
\r
77 this.selectRow(index, true);
\r
84 onHdMouseDown : function(e, t){
\r
85 if(t.className == 'x-grid3-hd-checker'){
\r
87 var hd = Ext.fly(t.parentNode);
\r
88 var isChecked = hd.hasClass('x-grid3-hd-checker-on');
\r
90 hd.removeClass('x-grid3-hd-checker-on');
\r
91 this.clearSelections();
\r
93 hd.addClass('x-grid3-hd-checker-on');
\r
100 renderer : function(v, p, record){
\r
101 return '<div class="x-grid3-row-checker"> </div>';
\r