开发者

ExtJS Gridpanel selected rows

开发者 https://www.devze.com 2023-03-01 20:44 出处:网络
I am design ExtJs Gridpanel with Checkboxes... How to get checked records for save the da开发者_如何学PythontaUse getSelections to get all selected records and getSelected to get the first record.

I am design ExtJs Gridpanel with Checkboxes... How to get checked records for save the da开发者_如何学Pythonta


Use getSelections to get all selected records and getSelected to get the first record.

var selected = checkBoxSelectionModelObj.getSelections();

for (var i = 0; i < selected.length; i++)
{
    alert(selected[i].data.code);
}


In ExtJs docs provide method to get selected record in grid grid.getSelection(). You can refer ExtJs docs

I have create small demo to show you, how it work. Sencha fiddle example

var store = Ext.create('Ext.data.Store', {
        fields: ['name', 'email', 'phone'],
        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'
        }, {
            name: 'AMargeia',
            email: 'marge@simpsons.com',
            phone: '555-222-1254'
        }]
    });

    Ext.create('Ext.grid.Panel', {
        title: 'Simpsons',
        store: store,
        id: 'testGrid',
        columns: [{
            text: 'Name',
            dataIndex: 'name'
        }, {
            text: 'Email',
            dataIndex: 'email',
            flex: 1
        }, {
            text: 'Phone',
            dataIndex: 'phone'
        }],
        height: 200,
        width: 400,
        renderTo: Ext.getBody(),
        selModel: {
            checkOnly: false,
            injectCheckbox: 'last',
            mode: 'SIMPLE'
        },
        selType: 'checkboxmodel',
        buttons: [{
            text: 'Select All',
            handler: function () {
                Ext.getCmp('testGrid').getSelectionModel().selectAll();
            }
        }, {
            text: 'Deselect All',
            handler: function () {
                Ext.getCmp('testGrid').getSelectionModel().deselectAll();
            }
        },{
            text:'Print Selected Recod',
            handler:function(){
                var selection = Ext.getCmp('testGrid').getSelection();
                if(selection.length){
                    let name='';
                    selection.map(item=>{
                        name+=item.get('name')+'<br>';
                    });
                    Ext.Msg.alert('Selected Record',name);
                }else{
                    Ext.Msg.alert('Error','Please select record');
                }
            }
        }]
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消