4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-selection-CheckboxModel'>/**
19 </span> * @class Ext.selection.CheckboxModel
20 * @extends Ext.selection.RowModel
22 * A selection model that renders a column of checkboxes that can be toggled to
23 * select or deselect rows. The default mode for this selection model is MULTI.
25 * The selection model will inject a header for the checkboxes in the first view
26 * and according to the 'injectCheckbox' configuration.
28 Ext.define('Ext.selection.CheckboxModel', {
29 alias: 'selection.checkboxmodel',
30 extend: 'Ext.selection.RowModel',
32 <span id='Ext-selection-CheckboxModel-cfg-mode'> /**
33 </span> * @cfg {String} mode
35 * Valid values are SINGLE, SIMPLE, and MULTI. Defaults to 'MULTI'
39 <span id='Ext-selection-CheckboxModel-cfg-injectCheckbox'> /**
40 </span> * @cfg {Number/Boolean/String} injectCheckbox
41 * Instructs the SelectionModel whether or not to inject the checkbox header
42 * automatically or not. (Note: By not placing the checkbox in manually, the
43 * grid view will need to be rendered 2x on initial render.)
44 * Supported values are a Number index, false and the strings 'first' and 'last'.
48 <span id='Ext-selection-CheckboxModel-cfg-checkOnly'> /**
49 </span> * @cfg {Boolean} checkOnly <tt>true</tt> if rows can only be selected by clicking on the
57 checkerOnCls: Ext.baseCSSPrefix + 'grid-hd-checker-on',
59 bindComponent: function(view) {
63 me.callParent(arguments);
64 if (!me.hasLockedHeader() || view.headerCt.lockedCt) {
65 // if we have a locked header, only hook up to the first
66 view.headerCt.on('headerclick', me.onHeaderClick, me);
68 me.mon(view.ownerCt, 'reconfigure', me.addCheckbox, me);
72 hasLockedHeader: function(){
73 var hasLocked = false;
74 Ext.each(this.views, function(view){
75 if (view.headerCt.lockedCt) {
83 <span id='Ext-selection-CheckboxModel-method-addCheckbox'> /**
84 </span> * Add the header checkbox to the header row
86 * @param {Boolean} initial True if we're binding for the first time.
88 addCheckbox: function(initial){
90 checkbox = me.injectCheckbox,
92 headerCt = view.headerCt;
94 if (checkbox !== false) {
95 if (checkbox == 'first') {
97 } else if (checkbox == 'last') {
98 checkbox = headerCt.getColumnCount();
100 headerCt.add(checkbox, me.getHeaderConfig());
103 if (initial !== true) {
108 <span id='Ext-selection-CheckboxModel-method-toggleUiHeader'> /**
109 </span> * Toggle the ui header between checked and unchecked state.
110 * @param {Boolean} isChecked
113 toggleUiHeader: function(isChecked) {
114 var view = this.views[0],
115 headerCt = view.headerCt,
116 checkHd = headerCt.child('gridcolumn[isCheckerHd]');
120 checkHd.el.addCls(this.checkerOnCls);
122 checkHd.el.removeCls(this.checkerOnCls);
127 <span id='Ext-selection-CheckboxModel-method-onHeaderClick'> /**
128 </span> * Toggle between selecting all and deselecting all when clicking on
131 onHeaderClick: function(headerCt, header, e) {
132 if (header.isCheckerHd) {
134 var isChecked = header.el.hasCls(Ext.baseCSSPrefix + 'grid-hd-checker-on');
136 // We have to supress the event or it will scrollTo the change
137 this.deselectAll(true);
139 // We have to supress the event or it will scrollTo the change
140 this.selectAll(true);
145 <span id='Ext-selection-CheckboxModel-method-getHeaderConfig'> /**
146 </span> * Retrieve a configuration to be used in a HeaderContainer.
147 * This should be used when injectCheckbox is set to false.
149 getHeaderConfig: function() {
155 width: me.headerWidth,
162 cls: Ext.baseCSSPrefix + 'column-header-checkbox ',
163 renderer: Ext.Function.bind(me.renderer, me),
164 locked: me.hasLockedHeader()
168 <span id='Ext-selection-CheckboxModel-method-renderer'> /**
169 </span> * Generates the HTML to be rendered in the injected checkbox column for each row.
170 * Creates the standard checkbox markup by default; can be overridden to provide custom rendering.
171 * See {@link Ext.grid.column.Column#renderer} for description of allowed parameters.
173 renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {
174 metaData.tdCls = Ext.baseCSSPrefix + 'grid-cell-special';
175 return '<div class="' + Ext.baseCSSPrefix + 'grid-row-checker">&#160;</div>';
179 onRowMouseDown: function(view, record, item, index, e) {
182 checker = e.getTarget('.' + Ext.baseCSSPrefix + 'grid-row-checker');
184 if (!me.allowRightMouseSelection(e)) {
188 // checkOnly set, but we didn't click on a checker.
189 if (me.checkOnly && !checker) {
194 var mode = me.getSelectionMode();
195 // dont change the mode if its single otherwise
196 // we would get multiple selection
197 if (mode !== 'SINGLE') {
198 me.setSelectionMode('SIMPLE');
200 me.selectWithEvent(record, e);
201 me.setSelectionMode(mode);
203 me.selectWithEvent(record, e);
207 <span id='Ext-selection-CheckboxModel-method-onSelectChange'> /**
208 </span> * Synchronize header checker value as selection changes.
211 onSelectChange: function() {
212 this.callParent(arguments);
214 // check to see if all records are selected
215 var hdSelectStatus = this.selected.getCount() === this.store.getCount();
216 this.toggleUiHeader(hdSelectStatus);