3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 <div id="cls-Ext.grid.CheckboxSelectionModel"></div>/**
16 * @class Ext.grid.CheckboxSelectionModel
17 * @extends Ext.grid.RowSelectionModel
18 * A custom selection model that renders a column of checkboxes that can be toggled to select or deselect rows.
20 * @param {Object} config The configuration options
22 Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
24 <div id="cfg-Ext.grid.CheckboxSelectionModel-checkOnly"></div>/**
25 * @cfg {Boolean} checkOnly <tt>true</tt> if rows can only be selected by clicking on the
26 * checkbox column (defaults to <tt>false</tt>).
28 <div id="cfg-Ext.grid.CheckboxSelectionModel-header"></div>/**
29 * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the
30 * checkbox column. Defaults to:<pre><code>
31 * '<div class="x-grid3-hd-checker">&#160;</div>'</tt>
33 * The default CSS class of <tt>'x-grid3-hd-checker'</tt> displays a checkbox in the header
34 * and provides support for automatic check all/none behavior on header click. This string
35 * can be replaced by any valid HTML fragment, including a simple text string (e.g.,
36 * <tt>'Select Rows'</tt>), but the automatic check all/none behavior will only work if the
37 * <tt>'x-grid3-hd-checker'</tt> class is supplied.
39 header : '<div class="x-grid3-hd-checker"> </div>',
40 <div id="cfg-Ext.grid.CheckboxSelectionModel-width"></div>/**
41 * @cfg {Number} width The default width in pixels of the checkbox column (defaults to <tt>20</tt>).
44 <div id="cfg-Ext.grid.CheckboxSelectionModel-sortable"></div>/**
45 * @cfg {Boolean} sortable <tt>true</tt> if the checkbox column is sortable (defaults to
56 isColumn: true, // So that ColumnModel doesn't feed this through the Column constructor
58 constructor : function(){
59 Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments);
61 this.handleMouseDown = Ext.emptyFn;
66 initEvents : function(){
67 Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);
68 this.grid.on('render', function(){
69 Ext.fly(this.grid.getView().innerHd).on('mousedown', this.onHdMouseDown, this);
75 * Process and refire events routed from the GridView's processEvent method.
77 processEvent : function(name, e, grid, rowIndex, colIndex){
78 if (name == 'mousedown') {
79 this.onMouseDown(e, e.getTarget());
82 return Ext.grid.Column.prototype.processEvent.apply(this, arguments);
87 onMouseDown : function(e, t){
88 if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click
90 var row = e.getTarget('.x-grid3-row');
92 var index = row.rowIndex;
93 if(this.isSelected(index)){
94 this.deselectRow(index);
96 this.selectRow(index, true);
97 this.grid.getView().focusRow(index);
104 onHdMouseDown : function(e, t) {
105 if(t.className == 'x-grid3-hd-checker'){
107 var hd = Ext.fly(t.parentNode);
108 var isChecked = hd.hasClass('x-grid3-hd-checker-on');
110 hd.removeClass('x-grid3-hd-checker-on');
111 this.clearSelections();
113 hd.addClass('x-grid3-hd-checker-on');
120 renderer : function(v, p, record){
121 return '<div class="x-grid3-row-checker"> </div>';
124 onEditorSelect: function(row, lastRow){
125 if(lastRow != row && !this.checkOnly){
126 this.selectRow(row); // *** highlight newly-selected cell and update selection