使用selectionModel获取网格内的复选框值

问题描述 投票:1回答:1

如何从Ext.grid.Panel中的selectionModel获取复选框的值?

我找不到grid.getView()中的属性.getRow(0).cells [0]

enter image description here

extjs extjs6 extjs6-classic
1个回答
0
投票

您可以使用selModel获取所选记录,如下所示

Ext.application({
    name: 'Fiddle',

    launch: function () {

        Ext.define('User', {
            extend: 'Ext.data.Model',
            fields: ['name', 'email', 'phone']
        });

        var userStore = Ext.create('Ext.data.Store', {
            model: 'User',
            data: [{
                    name: 'Lisa',
                    email: '[email protected]',
                    phone: '555-111-1224'
                }, {
                    name: 'Bart',
                    email: '[email protected]',
                    phone: '555-222-1234'
                }, {
                    name: 'Homer',
                    email: '[email protected]',
                    phone: '555-222-1244'
                }, {
                    name: 'Marge',
                    email: '[email protected]',
                    phone: '555-222-1254'
                }, {
                    name: 'Shreya',
                    email: '[email protected]',
                    phone: '555-222-1254'
                }

            ]
        });

        Ext.create({
                xtype: 'panel',
                title: 'Grid Panel',
                renderTo: Ext.getBody(),
                items: [{
                    xtype: 'grid',
                    id: 'mygrid',
                    store: userStore,
                    storeId: 'mystore',
                    width: 400,
                    height: 200,
                    selModel: {
                        selType: 'checkboxmodel',
                        checkOnly: true,
                        injectCheckbox: 0,
                        showHeaderCheckbox: false,
                        listeners: {

                        }
                    },
                    title: 'Application Users',
                    columns: [{
                        text: 'Name',
                        width: 100,
                        sortable: false,
                        hideable: false,
                        dataIndex: 'name'
                    }, {
                        text: 'Email Address',
                        width: 150,
                        dataIndex: 'email',
                        hidden: true
                    }, {
                        text: 'Phone Number',
                        flex: 1,
                        dataIndex: 'phone'
                    }]
                },{
                    xtype: 'panel',
                    items: [{
                        xtype: 'button',
                        text: 'get selected record',
                        handler: function() {
                            var myGrid = Ext.getCmp('mygrid');
                            var selections = myGrid.getSelections();
                            console.log(selections);
                        }
                    }]
                }]
            })
            //Ext.Msg.alert('Fiddle', 'Welcome to Sencha Fiddle!');
    }
});

链接到工作小提琴:https://fiddle.sencha.com/#view/editor&fiddle/2l15

© www.soinside.com 2019 - 2024. All rights reserved.