单击headerCheckbox时,不会为网格行调用checkcolumn事件(Extjs 6.6)

14ifxucb  于 2022-11-05  发布在  其他
关注(0)|答案(1)|浏览(145)

我在一个网格中添加了headerCheckbox,以获得Select/Deselect All的功能。还向checkcolumn添加了checkchange事件。当我手动选择/取消选择任何复选框时,该事件工作正常,但当我通过标题复选框进行选择时,该事件不触发。
因此,我的要求是,只要复选框中的选择发生变化,就应该触发事件。
这是我在Grid中的专栏:

{     
      xtype: 'checkcolumn',
      dataIndex: 'xyz',
      text: '',
      headerCheckbox: true,
      width: 25,
      stopSelection: true,
      sortable: false,
      draggable: false,
      resizable: false,
      menuDisabled: true,
      hideable: false
}

控制器中的事件:

control: {
    'checkcolumn':{
        checkchange: 'onCheckChange'
    }
},

onCheckChange : function ( checkbox, rowIndex, checked, record, e, eOpts ) {
    console.log(record);
}
s2j5cfk0

s2j5cfk01#

要捕获列标题检查更改事件,您需要侦听'headercheckchange':

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

Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
    height: 200,
    width: 400,
    renderTo: Ext.getBody(),
    store: store,
    columns: [{
        text: 'Name',
        dataIndex: 'name'
    }, {
        text: 'Email',
        dataIndex: 'email',
        flex: 1
    }, {
        text: 'Phone',
        dataIndex: 'phone'
    }, {
        xtype: 'checkcolumn',
        headerCheckbox: true,
        text: 'Active',
        dataIndex: 'active',
        listeners: {
            headercheckchange: function(checkColumn, checked) {
                console.log("Header Checkbox change event: ", checked);
            },
            checkchange: function(checkboxColumn, rowIndex, checked, record, e, eOpts ) {
                console.log("Grid body column checkbox change event: ", rowIndex, checked, record);
            }
        }
    }]
});

相关问题