当前位置: 代码迷 >> Web前端 >> Combox上拉GridPanel菜单
  详细解决方案

Combox上拉GridPanel菜单

热度:285   发布时间:2012-09-12 09:21:30.0
Combox下拉GridPanel菜单
extjs Combox下拉GridPanel菜单

Ext.onReady(function(){
      Ext.BLANK_IMAGE_URL = wroot+'ext-3.2.0/resources/images/default/s.gif';

//

var data=[['1','非诚勿扰'],['2','让子弹飞'],['3','锦衣卫'],['4','狄仁杰4']];



// 控制gridpanel  列表行 为只能选择一行

var  rsm = new Ext.grid.RowSelectionModel({   singleSelect:true     });



var store = new Ext.data.Store({
   autoDestroy: true,
   proxy:new Ext.data.MemoryProxy(data),
   reader:new Ext.data.ArrayReader({},[
       {name:'mid'},
       {name:'mname'}
   ])
});



var grid = new Ext.grid.GridPanel({
      width:600,
      height: 200,
     frame: true,
     border:true,
     //enableHdMenu:false,
     store: store,
     enableColumnMove:false,   //支持列移动
     enableColumnResize:true,
      autoExpandColumn : true,
      trackMouseOver : true,
      viewConfig:{
               forceFit:true
     },
  sm:rsm ,
  tbar:[{text:'确定一'},'-',new Ext.form.TextField({id: 'paramCnName',width:60}),{text:'查找一'}],
  cm: new Ext.grid.ColumnModel([
        new Ext.grid.RowNumberer(),
       {header:'编号',dataIndex:'mid', sortable: true},
       {header:'姓名',dataIndex:'mname', sortable: true}
  ]),

// 远程数据 才有效果

  bbar:new Ext.PagingToolbar({
      pageSize:10,
      store:store,
      displayInfo:true,
      displayMsg:'显示第{0} 条 到 {1} 条记录,一共{2}条',
      emptyMsg:'无记录'
  }),

  listeners:{
    rowdblclick:function(grid , rowIndex ,e){
       showMenu .hide();
       var rowOptions = grid.getSelectionModel().getSelections();
        for(var i=0; i< rowOptions.length; i++){
            var uid = rowOptions[i].get('mid');
            var uname = rowOptions[i].get('mname');
            comb.setValue(uid);
            comb.setRawValue(uname);
        }
    }
  }
});



var showMenu = new Ext.menu.Menu({
     items : [grid]
});



var comb = new Ext.form.ComboBox({
    renderTo:'combox-panel-grid',  /*渲染到一个容器里*/
    width:600,
    triggerAction: 'all',
    typeAhead: true,
    lazyRender:true,
    editable:true,
emptyText:'请选择...',
    valueField: 'mid',
    displayField: 'mname',
    tpl:'<div id="panel-item"></div>',
    mode: 'local',
    onSelect:Ext.emptyFn ,
    store:new Ext.data.ArrayStore({ fields: ['mid','mname'],  data:[[]] }),
    listeners:{
      expand:function(combo){

        //重要
        if(this.menu == null) {
           this.menu = showMenu;
        }
        store.load();
        this.menu.show(this.el, "tl-bl?");

       // this.menu.show(combo.getEl());

      }
    }
});



});



  <div id="combox-panel-grid"></div>



ComboBox组件中实现下拉树效果:


var combtree = new Ext.form.ComboBox({  
        store:new Ext.data.SimpleStore({fields:[],data:[[]]}),  
        editable:false,  
        mode: 'local',  
        triggerAction:'all',  
        maxHeight: 200,  
        tpl: "<tpl for='.'><div style='height:200px'><div id='tree'></div></div></tpl>",  
        selectedClass:'',  
        onSelect:Ext.emptyFn  
    });  
    var tree = new Ext.tree.TreePanel({  
        loader:new Ext.tree.TreeLoader(),
        border:false,  
         root:new Ext.tree.AsyncTreeNode({text: '目录',id:'0'}) ,
         listeners:{
           beforeload:function(node){
                   this.loader.dataUrl = '../../nodes.action?ID=' + node.id;
           }} 
      });  
      tree.on('click',function(node){  
          combtree.setValue(node.text);  
          combtree.collapse();  
      });  
    combtree.on('expand',function(){  
        tree.render('tree');  
      });  
    combtree.render('combtree');