Search code examples
javascriptextjsgridsencha-touch

Confirmation box click No button, uncheck the Grid check box cell ExtJs


In Grid, I want to uncheck the checkbox if in confirmation box, I click 'No' button, I am trying by setting checked false. Its not working.

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

Action is defined in controller file

'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;  
                            }
                        }
                    });
                }    
            }
        }
    });
}

Solution

  • Try to use listeners for checkchange of checkcolumn

    I have created an demo how it is working in ExtJs4.2 you can see here Sencha Fiddle

    Hope it will help you to solve your problem.

    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()
        });