X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/0494b8d9b9bb03ab6c22b34dae81261e3cd7e3e6..7a654f8d43fdb43d78b63d90528bed6e86b608cc:/examples/ux/CheckColumn.js diff --git a/examples/ux/CheckColumn.js b/examples/ux/CheckColumn.js index 5dd143ea..bbe3421c 100644 --- a/examples/ux/CheckColumn.js +++ b/examples/ux/CheckColumn.js @@ -1,71 +1,77 @@ -/*! - * Ext JS Library 3.3.1 - * Copyright(c) 2006-2010 Sencha Inc. - * licensing@sencha.com - * http://www.sencha.com/license - */ -Ext.ns('Ext.ux.grid'); - /** - * @class Ext.ux.grid.CheckColumn - * @extends Ext.grid.Column - *

A Column subclass which renders a checkbox in each column cell which toggles the truthiness of the associated data field on click.

+ * @class Ext.ux.CheckColumn + * @extends Ext.grid.column.Column + *

A Header subclass which renders a checkbox in each column cell which toggles the truthiness of the associated data field on click.

*

Note. As of ExtJS 3.3 this no longer has to be configured as a plugin of the GridPanel.

*

Example usage:

*

-var cm = new Ext.grid.ColumnModel([{
-       header: 'Foo',
-       ...
-    },{
-       xtype: 'checkcolumn',
-       header: 'Indoor?',
-       dataIndex: 'indoor',
-       width: 55
-    }
-]);
-
 // create the grid
-var grid = new Ext.grid.EditorGridPanel({
+var grid = Ext.create('Ext.grid.Panel', {
     ...
-    colModel: cm,
+    columns: [{
+           text: 'Foo',
+           ...
+        },{
+           xtype: 'checkcolumn',
+           text: 'Indoor?',
+           dataIndex: 'indoor',
+           width: 55
+        }
+    ]
     ...
 });
  * 
* In addition to toggling a Boolean value within the record data, this - * class toggles a css class between 'x-grid3-check-col' and - * 'x-grid3-check-col-on' to alter the background image used for - * a column. + * class adds or removes a css class 'x-grid-checked' on the td + * based on whether or not it is checked to alter the background image used + * for a column. */ -Ext.ux.grid.CheckColumn = Ext.extend(Ext.grid.Column, { +Ext.define('Ext.ux.CheckColumn', { + extend: 'Ext.grid.column.Column', + alias: 'widget.checkcolumn', + + constructor: function() { + this.addEvents( + /** + * @event checkchange + * Fires when the checked state of a row changes + * @param {Ext.ux.CheckColumn} this + * @param {Number} rowIndex The row index + * @param {Boolean} checked True if the box is checked + */ + 'checkchange' + ); + this.callParent(arguments); + }, /** * @private * Process and refire events routed from the GridView's processEvent method. */ - processEvent : function(name, e, grid, rowIndex, colIndex){ - if (name == 'mousedown') { - var record = grid.store.getAt(rowIndex); - record.set(this.dataIndex, !record.data[this.dataIndex]); - return false; // Cancel row selection. + processEvent: function(type, view, cell, recordIndex, cellIndex, e) { + if (type == 'mousedown' || (type == 'keydown' && (e.getKey() == e.ENTER || e.getKey() == e.SPACE))) { + var record = view.panel.store.getAt(recordIndex), + dataIndex = this.dataIndex, + checked = !record.get(dataIndex); + + record.set(dataIndex, checked); + this.fireEvent('checkchange', this, recordIndex, checked); + // cancel selection. + return false; } else { - return Ext.grid.ActionColumn.superclass.processEvent.apply(this, arguments); + return this.callParent(arguments); } }, - renderer : function(v, p, record){ - p.css += ' x-grid3-check-col-td'; - return String.format('
 
', v ? '-on' : ''); - }, + // Note: class names are not placed on the prototype bc renderer scope + // is not in the header. + renderer : function(value){ + var cssPrefix = Ext.baseCSSPrefix, + cls = [cssPrefix + 'grid-checkheader']; - // Deprecate use as a plugin. Remove in 4.0 - init: Ext.emptyFn + if (value) { + cls.push(cssPrefix + 'grid-checkheader-checked'); + } + return '
 
'; + } }); - -// register ptype. Deprecate. Remove in 4.0 -Ext.preg('checkcolumn', Ext.ux.grid.CheckColumn); - -// backwards compat. Remove in 4.0 -Ext.grid.CheckColumn = Ext.ux.grid.CheckColumn; - -// register Column xtype -Ext.grid.Column.types.checkcolumn = Ext.ux.grid.CheckColumn; \ No newline at end of file