2

我有EditorGridPanel,网格的ColumnModel 包括TextField、ComboBox 和CheckBox。编辑 TextField 或 ComboBox 后,会触发包含有关已编辑字段的详细信息的“afteredit”事件。当我选中/取消选中 CheckBox 字段时,没有任何事件可以提供有关按下哪个 CheckBox 的任何详细信息。

4

2 回答 2

3

选择模型呈现一列复选框,可以切换以选择或取消选择网格中的行。

尝试在复选框选择模型上应用侦听器。

文档:Ext.selection.CheckboxModel-event-selectionchange

参考:例子

于 2012-05-29T06:18:31.050 回答
1

使用来自的checkchange事件Ext.ux.CheckColumn。这给出了rowIndex。

编辑

如果您在 2.2 中进行更多开发,我建议您升级。但是如果你不能,你总是可以尝试添加一个覆盖,或者扩展Ext.ux.CheckColumn以包含更高版本的事件。我确信必须调整此代码以使其与 2.2 兼容,但这是一个包含所需事件的覆盖示例——我意识到我什至不确定 2.2 是否具有该Ext.override方法,您必须检查您的文档(checkchange 代码直接来自 4.1 API):

Ext.override(Ext.ux.CheckChange, {
    constructor: function() {
        this.addEvents(
            /**
             * @event beforecheckchange
             * Fires when before checked state of a row changes.
             * The change may be vetoed by returning `false` from a listener.
             * @param {Ext.ux.CheckColumn} this CheckColumn
             * @param {Number} rowIndex The row index
             * @param {Boolean} checked True if the box is to be checked
             */
            'beforecheckchange',
            /**
             * @event checkchange
             * Fires when the checked state of a row changes
             * @param {Ext.ux.CheckColumn} this CheckColumn
             * @param {Number} rowIndex The row index
             * @param {Boolean} checked True if the box is now checked
             */
            'checkchange'
        );
        this.callParent(arguments);
    },

    /**
     * @private
     * Process and refire events routed from the GridView's processEvent method.
     */
    processEvent: function(type, view, cell, recordIndex, cellIndex, e) {
        var me = this,
            key = type === 'keydown' && e.getKey(),
            mousedown = type == 'mousedown';

        if (mousedown || (key == e.ENTER || key == e.SPACE)) {
            var record = view.panel.store.getAt(recordIndex),
                dataIndex = me.dataIndex,
                checked = !record.get(dataIndex);

            // Allow apps to hook beforecheckchange
            if (me.fireEvent('beforecheckchange', me, recordIndex, checked) !== false) {
                record.set(dataIndex, checked);
                me.fireEvent('checkchange', me, recordIndex, checked);

                // Mousedown on the now nonexistent cell causes the view to blur, so stop it continuing.
                if (mousedown) {
                    e.stopEvent();
                }

                // Selection will not proceed after this because of the DOM update caused by the record modification
                // Invoke the SelectionModel unless configured not to do so
                if (!me.stopSelection) {
                    view.selModel.selectByPosition({
                        row: recordIndex,
                        column: cellIndex
                    });
                }

                // Prevent the view from propagating the event to the selection model - we have done that job.
                return false;
            } else {
                // Prevent the view from propagating the event to the selection model if configured to do so.
                return !me.stopSelection;
            }
        } else {
            return me.callParent(arguments);
        }
    },
});
于 2012-05-29T08:08:25.687 回答