确认框单击否按钮,取消选中网格复选框单元格ExtJs

时间:2017-09-22 00:46:25

标签: javascript extjs grid sencha-touch

在Grid中,我想取消选中复选框,如果在确认框中,我单击“否”按钮,我正在尝试设置选中的false。它不起作用。

Ext.create('Ext.grid.Panel', {   
columns  : [  
 {
        xtype: 'checkcolumn',
        id: 'device',
        text: 'Device',
        dataIndex: 'device',
        checkboxToggle: true,
        hidden: false,
        action: "checkchange"
} ]
});

动作在控制器文件中定义

'Grid [action=checkchange]' {
    checkchange: function (column, rowIndex) {
      if (checked == true) {
                    Ext.MessageBox.confirm({
                        cls: 'window-alert',
                        buttons: Ext.Msg.YESNO,
                        msg: 'Are you sure?',
                        fn: function (btn) {
                            if (btn === 'yes') {

                            } else {
                                var grid = column.up('Grid');
                                var gridStore = grid.getStore();
                                var rec = gridStore.getAt(rowIndex);
                               rec.get('device').checked = false;  
                            }
                        }
                    });
                }    
            }
        }
    });
}

1 个答案:

答案 0 :(得分:0)

  

尝试将侦听器用于checkcolumn的checkchange

我已经创建了一个演示如何在ExtJs4.2中工作,你可以在这里看到Sencha Fiddle

希望它能帮助您解决问题。

var store = Ext.create('Ext.data.Store', {
        fields: ['name', 'email', 'phone', {
            name: 'isChecked',
            type: 'boolean',
            defaultValue: false
        }],
        data: [{
            name: 'Lisa',
            email: 'lisa@simpsons.com',
            phone: '555-111-1224'
        }, {
            name: 'Bart',
            email: 'bart@simpsons.com',
            phone: '555-222-1234'
        }, {
            name: 'Homer',
            email: 'homer@simpsons.com',
            phone: '555-222-1244'
        }, {
            name: 'Marge',
            email: 'marge@simpsons.com',
            phone: '555-222-1254'
        }]
    });

    Ext.create('Ext.grid.Panel', {
        title: 'Simpsons',
        store: store,
        columns: [{
            xtype: 'checkcolumn',
            width: 30,
            sortable: false,
            dataIndex: 'isChecked',
            editor: {
                xtype: 'checkbox',
                cls: 'x-grid-checkheader-editor'
            },
            listeners: {
                checkchange: function (column, rowIndex, checked, record, e, eOpts) {
                    if (checked) {
                        Ext.MessageBox.confirm({
                            cls: 'window-alert',
                            buttons: Ext.Msg.YESNO,
                            msg: 'Are you sure?',
                            fn: function (btn) {
                                if (btn === 'yes') {
                                    column.up('grid').getSelectionModel().select(record, true, true)
                                } else {
                                    column.up('grid').getStore().getAt(rowIndex).set('isChecked', false);
                                }
                            }
                        });
                    }
                }
            }
        }, {
            text: 'Name',
            dataIndex: 'name'
        }, {
            text: 'Email',
            dataIndex: 'email',
            flex: 1
        }, {
            text: 'Phone',
            dataIndex: 'phone'
        }],
        height: 500,
        width: '100%',
        renderTo: Ext.getBody()
    });