3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
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.
12 * @param {Object} config The configuration options
14 Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
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>).
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 * '<div class="x-grid3-hd-checker">&#160;</div>'</tt>
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.
31 header : '<div class="x-grid3-hd-checker"> </div>',
33 * @cfg {Number} width The default width in pixels of the checkbox column (defaults to <tt>20</tt>).
37 * @cfg {Boolean} sortable <tt>true</tt> if the checkbox column is sortable (defaults to
49 constructor : function(){
50 Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments);
53 this.handleMouseDown = Ext.emptyFn;
58 initEvents : function(){
59 Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);
60 this.grid.on('render', function(){
61 var view = this.grid.getView();
62 view.mainBody.on('mousedown', this.onMouseDown, this);
63 Ext.fly(view.innerHd).on('mousedown', this.onHdMouseDown, this);
68 // If handleMouseDown was called from another event (enableDragDrop), set a flag so
69 // onMouseDown does not process it a second time
70 handleMouseDown : function() {
71 Ext.grid.CheckboxSelectionModel.superclass.handleMouseDown.apply(this, arguments);
72 this.mouseHandled = true;
76 onMouseDown : function(e, t){
77 if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click
79 var row = e.getTarget('.x-grid3-row');
81 // mouseHandled flag check for a duplicate selection (handleMouseDown) call
82 if(!this.mouseHandled && row){
83 var index = row.rowIndex;
84 if(this.isSelected(index)){
85 this.deselectRow(index);
87 this.selectRow(index, true);
88 this.grid.getView().focusRow(index);
92 this.mouseHandled = false;
96 onHdMouseDown : function(e, t){
97 if(t.className == 'x-grid3-hd-checker'){
99 var hd = Ext.fly(t.parentNode);
100 var isChecked = hd.hasClass('x-grid3-hd-checker-on');
102 hd.removeClass('x-grid3-hd-checker-on');
103 this.clearSelections();
105 hd.addClass('x-grid3-hd-checker-on');
112 renderer : function(v, p, record){
113 return '<div class="x-grid3-row-checker"> </div>';