X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/b37ceabb82336ee82757cd32efe353cfab8ec267..f5240829880f87e0cf581c6a296e436fdef0ef80:/examples/ux/CheckColumn.js diff --git a/examples/ux/CheckColumn.js b/examples/ux/CheckColumn.js index 4990d84d..dce007c0 100644 --- a/examples/ux/CheckColumn.js +++ b/examples/ux/CheckColumn.js @@ -1,5 +1,5 @@ /*! - * Ext JS Library 3.2.2 + * Ext JS Library 3.3.0 * Copyright(c) 2006-2010 Ext JS, Inc. * licensing@extjs.com * http://www.extjs.com/license @@ -8,77 +8,64 @@ Ext.ns('Ext.ux.grid'); /** * @class Ext.ux.grid.CheckColumn - * @extends Object - * GridPanel plugin to add a column with check boxes to a grid. + * @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.

+ *

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

*

Example usage:

*

-// create the column
-var checkColumn = new Ext.grid.CheckColumn({
-   header: 'Indoor?',
-   dataIndex: 'indoor',
-   id: 'check',
-   width: 55
-});
-
-// add the column to the column model
 var cm = new Ext.grid.ColumnModel([{
        header: 'Foo',
        ...
-    },
-    checkColumn
+    },{
+       xtype: 'checkcolumn',
+       header: 'Indoor?',
+       dataIndex: 'indoor',
+       width: 55
+    }
 ]);
 
 // create the grid
 var grid = new Ext.grid.EditorGridPanel({
     ...
-    cm: cm,
-    plugins: [checkColumn], // include plugin
+    colModel: cm,
     ...
 });
  * 
- * In addition to storing a Boolean value within the record data, this + * 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. */ -Ext.ux.grid.CheckColumn = function(config){ - Ext.apply(this, config); - if(!this.id){ - this.id = Ext.id(); - } - this.renderer = this.renderer.createDelegate(this); -}; +Ext.ux.grid.CheckColumn = Ext.extend(Ext.grid.Column, { -Ext.ux.grid.CheckColumn.prototype ={ - init : function(grid){ - this.grid = grid; - this.grid.on('render', function(){ - var view = this.grid.getView(); - view.mainBody.on('mousedown', this.onMouseDown, this); - }, this); - }, - - onMouseDown : function(e, t){ - if(Ext.fly(t).hasClass(this.createId())){ - e.stopEvent(); - var index = this.grid.getView().findRowIndex(t); - var record = this.grid.store.getAt(index); + /** + * @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. + } else { + return Ext.grid.ActionColumn.superclass.processEvent.apply(this, arguments); } }, renderer : function(v, p, record){ p.css += ' x-grid3-check-col-td'; - return String.format('
 
', v ? '-on' : '', this.createId()); + return String.format('
 
', v ? '-on' : ''); }, - - createId : function(){ - return 'x-grid3-cc-' + this.id; - } -}; -// register ptype + // Deprecate use as a plugin. Remove in 4.0 + init: Ext.emptyFn +}); + +// register ptype. Deprecate. Remove in 4.0 Ext.preg('checkcolumn', Ext.ux.grid.CheckColumn); -// backwards compat -Ext.grid.CheckColumn = Ext.ux.grid.CheckColumn; \ No newline at end of file +// 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