PageSourceSearch

https://secvirtual.autonoma.pt/netpa/js/extjs_4.x/extjs/examples/ux/CheckColumn.js?v=24.0.6-10

js autonoma.pt collected 2026-09-24 19:56:51 UTC 4,127 bytes, 117 lines download raw bytes

1/**
2 * @class Ext.ux.CheckColumn
3 * @extends Ext.grid.column.Column
4 * A Header subclass which renders a checkbox in each column cell which toggles the truthiness of the associated data field on click.
5 *
6 * Example usage:
7 * 
8 *    // create the grid
9 *    var grid = Ext.create('Ext.grid.Panel', {
10 *        ...
11 *        columns: [{
12 *           text: 'Foo',
13 *           ...
14 *        },{
15 *           xtype: 'checkcolumn',
16 *           text: 'Indoor?',
17 *           dataIndex: 'indoor',
18 *           width: 55
19 *        }]
20 *        ...
21 *    });
22 *
23 * In addition to toggling a Boolean value within the record data, this
24 * class adds or removes a css class <tt>'x-grid-checked'</tt> on the td
25 * based on whether or not it is checked to alter the background image used
26 * for a column.
27 */
28Ext.define('Ext.ux.CheckColumn', {
29    extend: 'Ext.grid.column.Column',
30    alias: 'widget.checkcolumn',
31
32    /**
33     * @cfg {Boolean} [stopSelection=true]
34     * Prevent grid selection upon mousedown.
35     */
36    stopSelection: true,
37
38    tdCls: Ext.baseCSSPrefix + 'grid-cell-checkcolumn',
39
40    constructor: function() {
41        this.addEvents(
42            /**
43             * @event beforecheckchange
44             * Fires when before checked state of a row changes.
45             * The change may be vetoed by returning `false` from a listener.
46             * @param {Ext.ux.CheckColumn} this CheckColumn
47             * @param {Number} rowIndex The row index
48             * @param {Boolean} checked True if the box is to be checked
49             */
50            'beforecheckchange',
51            /**
52             * @event checkchange
53             * Fires when the checked state of a row changes
54             * @param {Ext.ux.CheckColumn} this CheckColumn
55             * @param {Number} rowIndex The row index
56             * @param {Boolean} checked True if the box is now checked
57             */
58            'checkchange'
59        );
60        this.callParent(arguments);
61    },
62
63    /**
64     * @private
65     * Process and refire events routed from the GridView's processEvent method.
66     */
67    processEvent: function(type, view, cell, recordIndex, cellIndex, e, record, row) {
68        var me = this,
69            key = type === 'keydown' && e.getKey(),
70            mousedown = type == 'mousedown';
71
72        if (mousedown || (key == e.ENTER || key == e.SPACE)) {
73            var dataIndex = me.dataIndex,
74                checked = !record.get(dataIndex);
75
76            // Allow apps to hook beforecheckchange
77            if (me.fireEvent('beforecheckchange', me, recordIndex, checked) !== false) {
78                record.set(dataIndex, checked);
79                me.fireEvent('checkchange', me, recordIndex, checked);
80
81                // Mousedown on the now nonexistent cell causes the view to blur, so stop it continuing.
82                if (mousedown) {
83                    e.stopEvent();
84                }
85
86                // Selection will not proceed after this because of the DOM update caused by the record modification
87                // Invoke the SelectionModel unless configured not to do so
88                if (!me.stopSelection) {
89                    view.selModel.selectByPosition({
90                        row: recordIndex,
91                        column: cellIndex
92                    });
93                }
94
95                // Prevent the view from propagating the event to the selection model - we have done that job.
96                return false;
97            } else {
98                // Prevent the view from propagating the event to the selection model if configured to do so.
99                return !me.stopSelection;
100            }
101        } else {
102            return me.callParent(arguments);
103        }
104    },
105
106    // Note: class names are not placed on the prototype bc renderer scope
107    // is not in the header.
108    renderer : function(value){
109        var cssPrefix = Ext.baseCSSPrefix,
110            cls = [cssPrefix + 'grid-checkheader'];
111
112        if (value) {
113            cls.push(cssPrefix + 'grid-checkheader-checked');
114        }
115        return '<div class="' + cls.join(' ') + '">&#160;</div>';
116    }
117});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.