extjs两个grid之间传值

2025-05-12 14:10:53
推荐回答(1个)
回答(1):



  
    
    
    
    
      
      Ext.onReady(function(){
        var sampleData,
            store1,
            store2,
            grid1,
            grid2,
            clms;

        sampleData=[{
            userId:1,
            name:'Zeng'
        },{
            userId:2,
            name:'Lee'
        },{
            userId:3,
            name:'Chang'
        }];

        store1=Ext.create('Ext.data.Store',{
           fields:['userId','name'],
           data:sampleData
        });
          
        store2=Ext.create('Ext.data.Store',{
           fields:['userId','name']
        });

        clms=[{
            dataIndex:'userId',
            text:'User ID'
        },{
            dataIndex:'name',
            text:'Name'
        }];

        grid1=Ext.create('Ext.grid.Panel',{
            store:store1,
            columns:clms,
            flex:1,
            selType:'checkboxmodel'
        });

        grid2=Ext.create('Ext.grid.Panel',{
            store:store2,
            columns:clms,
            flex:1,
            selType:'checkboxmodel'
        });


        Ext.create('Ext.panel.Panel',{
            layout:{
                type:'hbox',
                align:'stretch'
            },
            width:420,
            height:300,
            items:[grid1,{
                xtype:'container',
                flex:0.3,
                items:[{
                    xtype:'button',
                    text:'>>',
                    itemId:'move_right',
                    handler:function(){
                        var records=grid1.getSelectionModel().getSelection();
                        store1.remove(records);
                        store2.add(records);
                    }
                },{
                    xtype:'button',
                    text:'<<',
                    itemId:'move_left',
                    handler:function(){
                        var records=grid2.getSelectionModel().getSelection();
                        store2.remove(records);
                        store1.add(records);
                    }
                }]
            },grid2],
            renderTo:Ext.getBody()
        });
    });