]> git.proxmox.com Git - extjs.git/blame - extjs/examples/classic/simple-tasks/app/ux/StatusColumn.js
add extjs 6.0.1 sources
[extjs.git] / extjs / examples / classic / simple-tasks / app / ux / StatusColumn.js
CommitLineData
6527f429
DM
1/**\r
2 * @class SimpleTasks.ux.StatusColumn\r
3 * @extends Ext.grid.column.Column\r
4 * <p>A Header subclass which renders a checkbox in each column cell which toggles the truthiness of the associated data field on click.</p>\r
5 * <p><b>Note. As of Ext JS 3.3 this no longer has to be configured as a plugin of the GridPanel.</b></p>\r
6 * <p>Example usage:</p>\r
7 * <pre><code>\r
8// create the grid\r
9var grid = Ext.create('Ext.grid.Panel', {\r
10 ...\r
11 columns: [{\r
12 text: 'Foo',\r
13 ...\r
14 },{\r
15 xtype: 'statuscolumn',\r
16 text: 'Indoor?',\r
17 dataIndex: 'indoor',\r
18 width: 55\r
19 }\r
20 ]\r
21 ...\r
22});\r
23 * </code></pre>\r
24 * In addition to toggling a Boolean value within the record data, this\r
25 * class adds or removes a css class <tt>'x-grid-checked'</tt> on the td\r
26 * based on whether or not it is checked to alter the background image used\r
27 * for a column.\r
28 */\r
29Ext.define('SimpleTasks.ux.StatusColumn', {\r
30 extend: 'Ext.grid.column.Column',\r
31 xtype: 'statuscolumn',\r
32\r
33 tdCls: Ext.baseCSSPrefix + 'grid-cell-statuscolumn',\r
34 \r
35 /**\r
36 * @event checkchange\r
37 * Fires when the checked state of a row changes\r
38 * @param {SimpleTasks.ux.StatusColumn} this\r
39 * @param {Number} rowIndex The row index\r
40 * @param {Boolean} checked True if the box is checked\r
41 */\r
42\r
43 /**\r
44 * @private\r
45 * Process and refire events routed from the GridView's processEvent method.\r
46 */\r
47 processEvent: function(type, view, cell, recordIndex, cellIndex, e) {\r
48 var me = this,\r
49 cssPrefix = Ext.baseCSSPrefix,\r
50 target = Ext.get(e.getTarget()),\r
51 dataIndex, record, checked;\r
52\r
53 if (target.hasCls(cssPrefix + 'grid-statusheader-inner')) {\r
54 if(type === 'mousedown' && e.button === 0) {\r
55 record = view.panel.store.getAt(recordIndex);\r
56 dataIndex = me.dataIndex;\r
57 checked = !record.get(dataIndex);\r
58 record.set(dataIndex, checked);\r
59 me.fireEvent('checkchange', me, recordIndex, checked);\r
60 // cancel selection.\r
61 return false;\r
62 } else if(type === 'mouseover') {\r
63 target.parent().addCls(cssPrefix + 'grid-statusheader-over');\r
64 } else if(type === 'mouseout') {\r
65 target.parent().removeCls(cssPrefix + 'grid-statusheader-over');\r
66 }\r
67 } else {\r
68 return me.callParent(arguments);\r
69 }\r
70 },\r
71\r
72 // Note: class names are not placed on the prototype bc renderer scope\r
73 // is not in the header.\r
74 renderer : function(value){\r
75 var cssPrefix = Ext.baseCSSPrefix,\r
76 cls = [cssPrefix + 'grid-statusheader'];\r
77\r
78 if (value) {\r
79 cls.push(cssPrefix + 'grid-statusheader-checked');\r
80 }\r
81 return '<div class="' + cls.join(' ') + '"><div class="' + cssPrefix + 'grid-statusheader-inner' + '">&#160;</div></div>';\r
82 }\r
83});\r