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
48 isColumn: true, // So that ColumnModel doesn't feed this through the Column constructor
50 constructor : function(){
51 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 Ext.fly(this.grid.getView().innerHd).on('mousedown', this.onHdMouseDown, this);
67 * Process and refire events routed from the GridView's processEvent method.
69 processEvent : function(name, e, grid, rowIndex, colIndex){
70 if (name == 'mousedown') {
71 this.onMouseDown(e, e.getTarget());
74 return Ext.grid.Column.prototype.processEvent.apply(this, arguments);
79 onMouseDown : function(e, t){
80 if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click
82 var row = e.getTarget('.x-grid3-row');
84 var index = row.rowIndex;
85 if(this.isSelected(index)){
86 this.deselectRow(index);
88 this.selectRow(index, true);
89 this.grid.getView().focusRow(index);
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>';