在网格中选择哪条记录

时间:2013-12-16 18:20:47

标签: select extjs grid

我在我的代码中定义Ext.selection.CheckboxModel ....

var selModel = Ext.create('Ext.selection.CheckboxModel', {
    checkOnly: true,
    listeners: {
        selectionchange: function(sm, selections) {
            gridPanel.down('#removeButton').setDisabled(selections.length === 0);
            gridPanel.down('#imprimirButton').setDisabled(selections.length === 0);
        },
        deselect: function(model, record, index) {
            id = record.get('company');
            console.log(id);
            console.log(index);
        },
        select: function(model, record, index) {
            id = record.get('company');
            console.log(id);
            console.log(index);
        }
    }
});

我定义我的网格字段,包括要选择的字段....

var gridPanel = Ext.create('Ext.grid.Panel', {
        id:'button-grid',
        store: storePanel,
        columnLines: true,
        selModel: selModel,
        columns: [
            {text: "Company", flex: 1, sortable: true, dataIndex: 'company'},
            {text: "Price", width: 120, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
            {text: "Change", width: 120, sortable: true, dataIndex: 'change'},
            {text: "% Change", width: 120, sortable: true, dataIndex: 'pctChange'},
            {text: "Last Updated", width: 120, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
        ],

我的打印机按钮....

{
                itemId: 'imprimirButton',
                text:'Printer Something',
                tooltip:'Printer the selected item',
                disabled: true,
                listeners: {
                    click: function(){
                        storePanel.each(function(rec){
                            if(rec.data.chkd){
                                console.log(rec.get('company'));
                            }
                        });
                    }
                }
            }

选择记录后,如何知道所选记录的工作情况并打印出来?

问候和感谢....

2 个答案:

答案 0 :(得分:2)

使用gridPanel.getSelectionModel().getSelection()返回网格中当前所选记录的数组。

{
    itemId: 'imprimirButton',
    text:'Printer Something',
    tooltip:'Printer the selected item',
    disabled: true,
    listeners: {
        click: function(){
            var selection = gridPanel.getSelectionModel().getSelection();
            for( var i = 0; i < selection.length; i++) {
                console.log(rec.get('company'));
            }
        }
    }
}

答案 1 :(得分:0)

您可以使用gridPanel.getSelectionModel().getSelection()获取所选节点。

请在此处查看相关文档: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.selection.Model-method-getSelection