如何通过检查网格中的CheckBox获取详细信息?

时间:2012-05-29 06:02:22

标签: extjs

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

2 个答案:

答案 0 :(得分:3)

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

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

docs:Ext.selection.CheckboxModel-event-selectionchange

参考:example

答案 1 :(得分:1)

使用Ext.ux.CheckColumn中的checkchange事件。这给出了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);
        }
    },
});