首页 > 解决方案 > EXTJS:如何确定是否已单击数据网格中的标题复选框

问题描述

我想知道是否已单击 headerCheckbox(全选)。我在这里从 sencha fiddle 得到了这个例子:

https://fiddle.sencha.com/#fiddle/1gvv&view/editor

`Ext.application({ name: 'Fiddle', launch: function() {

    // Define our data model
    Ext.define('MyModel', {
        extend: 'Ext.data.Model',
        fields: ['firstField', 'secondField']
    });

    // Generate mock data
    var data = [{
        "firstField": "one",
        "secondField": "1"
    }, {
        "firstField": "two",
        "secondField": "2"
    }, {
        "firstField": "three",
        "secondField": "3"
    }, {
        "firstField": "four",
        "secondField": "4"
    }, {
        "firstField": "five",
        "secondField": "5"
    }];

    // create the Data Store
    var store = Ext.create('Ext.data.Store', {
        // destroy the store if the grid is destroyed
        autoDestroy: true,
        model: 'MyModel',
        proxy: {
            type: 'memory'
        },
        data: data
    });

    var sm = new Ext.selection.CheckboxModel({
        checkOnly: true,
        listeners: {
           selectionchange: 'onSelectionChange'
        }
    });

    var grid = Ext.create('Ext.grid.Panel', {
        store: store,
        selModel: sm,
        columns: [{
            header: 'firstField',
            dataIndex: 'firstField',
            flex: 1
        }, {
            header: 'secondField',
            dataIndex: 'secondField',
            flex: 1
        }],
        tbar: [{
            xtype: 'textfield',
            fieldLabel: 'firstField',
            itemId: 'mytextfield'
        }, {
            text: 'Select',
            handler: function() {
               // try to find the record having the firstField field as the entered one
                var selectedRecord = grid.getStore().findRecord('firstField', grid.down('#mytextfield').getValue()); 
               if (selectedRecord) {
                    grid.getSelectionModel().select(selectedRecord);
                }
            }
        }]
    });
    new Ext.window.Window({
        width: 700,
        height: 400,
        items: grid,
        layout: 'fit',
        closable: false
    }).show();


}

});`

我已经放了onSelectionChange监听器,但是要在里面放什么才能知道是否单击了全选?

感谢您的帮助。

标签: checkboxextjs6.5

解决方案


我今天在搜索完全相同的东西时遇到了你的问题。

经过一些尝试,这就是我得到的 -

煎茶小提琴

本质上,您需要获取checkcolumn然后查看allChecked针对它的属性是否设置为true


推荐阅读