`
isiqi
  • 浏览: 16049714 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

extjs Combobox级联

 
阅读更多

使用的extjs library 3.3.1,可以直接看效果,其中有一个是获取服务器端的时间的:

ClinicCostForm=Ext.extend(Ext.form.FormPanel,{
	yearCbo:null,//年度CBO
	statisticArray:[],//统计时间数组
	dateStatisticsCbo:null,//时间统计类型cbo
	statisticTimeCbo:null,//统计时间
	statisticModeCbo:null,//统计方式Cbo
	exportModeCbo:null,//导出方式
	constructor:function(){//构造方法
         //step one
		  this.initYearCbo();//初始化年度CBO 你懂得
		 //step two
		 this.initDateStatistic();//初始化时间统计类型
		 //step three
		 this.initStatisticArray();//初始化Store中的参数
		 //step four
		 this.initStatisticTimeCbo();//初始化统计时间Combobox 
		 //step five
		 this.initStatisticModeCbo();//初始化统计方式Cbo
		 //step six
		 this.initExportModeCbo();//初始化导出方式的Cbo
		 
		//
		ClinicCostForm.superclass.constructor.call(this,{
			 region:"north",
			 collapsible:true,//是否可以折叠
			 title:"医院住院病人查询",
			 collapsedTitle:true, // 折叠时候是否显示title
		     border:true,
			 height:120,
		     layout:'column',
		     border:false,
		     //----
			 items:[{//---i begin			
				    xtype : "panel",
					layout : "column",
					border : false,
					items:[
					       {
				    	    xtype:"panel",
				    	    layout:'form',
				    	    border:false,
				    	    width:130,
				    	    labelWidth:40,
				    		items:[this.yearCbo]   
						   },
						   {
					    	    xtype:"panel",
					    	    layout:'form',
					    	    border:false,
					    	    width:200,
					    	    labelWidth:80,
					    		items:[this.dateStatisticsCbo]   
						    },
						    {
		                	    xtype:"panel",
					    	    layout:'form',
					    	    border:false,
					    	    width:180,
					    	    labelWidth:40,
			        	       items:[{xtype:"datefield",fieldLabel:"日期",editable:false,name:"startDate",id:"startDate",format:'Y-m-d',width:120,disabled:true,hidden:true}]
		                   },
		                   {//FIXME 给日期添加隐藏,以及下一部分的Form元素的设置
		                	    xtype:"panel",
					    	    layout:'form',
					    	    border:false,
					    	    width:160,
					    	    labelWidth:20,
			        	       items:[{xtype:"datefield",fieldLabel:"至",editable:false,name:"endDate",id:"endDate",format:'Y-m-d',width:120,disabled:true,hidden:true}]
		                   },
						   {
							   xtype:"panel",
							   layout:'form',
							   border:false,
							   width:180,
							   labelWidth:60,
							   items:[this.statisticTimeCbo]   
						   },
						   {
							   xtype:"panel",
							   layout:'form',
							   border:false,
							   width:180,
							   labelWidth:60,
							   items:[this.statisticModeCbo]   
						   },
						   {
							   xtype:"panel",
							   layout:'form',
							   border:false,
							   width:80,
							   labelWidth:60,
							   items:[{xtype:'button',text:'统计计算',hideLabel:true}]   
						   },
						   {
							   xtype:"panel",
							   layout:'form',
							   border:false,
							   width:180,
							   labelWidth:60,
							   items:[this.exportModeCbo]   
						   },
						   {
							   xtype:"panel",
							   layout:'form',
							   border:false,
							   width:80,
							   labelWidth:60,
							   items:[{xtype:'button',text:'导出EXCEL',hideLabel:true}]   
						   }
					       ]
			       }]//--i end
		        //---
		});
	},
	//---初始化年度Combobox
	initYearCbo:function(){
	 //annual.append("{value:'0',year:'全部',selected:false},");
	 var store= new Ext.data.JsonStore({
		 autoLoad:true,
		 idProperty:'value',
		 url:'/his/clinic_cost_statistics!ajaxGetAnnual.action',
		 fields:[{name:"value"},{name:'year'},{name:'selected'}],
		 listeners:{
			 load:this.setYearCboDefault,
			 scope:this
		 }
	 });
	 
     //
     this.yearCbo=new Ext.form.ComboBox({
    	   fieldLabel:"年度",
			triggerAction:'all',
		    displayField:'year',
		    editable:true,
		    valueField:'value',
		    name:'dbyear',
		    id:'dbyear',
		    store:store,
		    width:60,
		    listeners:{
		    	select:this.onYearCboSelect,
		    	scope:this
		    }
     });
     
	},
	//--年度CBO设置默认值事件
	setYearCboDefault:function(){
		var store=this.yearCbo.getStore();
		for(var i=0;i<store.getCount();i++){
			var r=store.getAt(i).data;
			if((r.selected)){
				this.yearCbo.setValue(r.value);
				break;
			}
		}
	},
	//---初始化实践统计类型CBO
	initDateStatistic:function(){
		 //时间统计类型simpleStore
		 var store=new Ext.data.SimpleStore({
			 fields:['value','text'],
			 data:[['1','按年统计'],['2','按季统计'],['3','按月统计'],['4','按日统计']]
		 
		 });
		 
		 //初始化时间统计类型
		 this.dateStatisticsCbo=new Ext.form.ComboBox({
	    	   fieldLabel:"时间统计类型",
				triggerAction:'all',
			    displayField:'text',
			    editable:true,
			    valueField:'value',
			    name:'tjlx',
			    id:'tjlx',
			    store:store,
			    width:100,
			    value:'1',
			    mode:'local',
			    listeners:{
			    	select:this.onDateStatisticTypeSelect,
			    	scope:this
			    }
	     });
		 
		  
	},
	//--初始化统计时间CBO
	initStatisticTimeCbo:function(){
		 var store=new Ext.data.ArrayStore({
			 fields:['key','value'],
			 data:[['-1','本年度']]
		 });
		 
		 this.statisticTimeCbo=new Ext.form.ComboBox({
	    	   fieldLabel:"统计时间",
				triggerAction:'all',
			    displayField:'value',
			    editable:true,
			    valueField:'key',
			    name:'exaTimeType',
			    id:'exaTimeType',
			    store:store,
			    width:80,
			    value:'-1',
			    mode:'local'
	     });
		 
	},
	//初始化统计时间类型Store
	initStatisticArray:function(){
      this.statisticArray[0]=[{key:'0',value:'全部年度'}];
      this.statisticArray[1]=[{key:'-1',value:'本年度'}];
      this.statisticArray[2]=[{key:'0',value:"全部"},
                              {key:'1',value:"第一季度"},
                              {key:'2',value:"第二季度"},
                              {key:'3',value:"第三季度"},
                              {key:'4',value:"第四季度"}
				              ];
      this.statisticArray[3]=[{key:'0',value:'全部'},
                              {key:'1',value:'一月'},
                              {key:'2',value:'二月'},
                              {key:'3',value:'三月'},
                              {key:'4',value:'四月'},
                              {key:'5',value:'五月'},
                              {key:'6',value:'六月'},
                              {key:'7',value:'七月'},
                              {key:'8',value:'八月'},
                              {key:'9',value:'九月'},
                              {key:'10',value:'十月'},
                              {key:'11',value:'十一月'},
                              {key:'12',value:'十二月'}
				             ];
      this.statisticArray[4]=[{key:'0',value:'全部'}]; 
      
	},
	//--初始化统计方式Combobox
	initStatisticModeCbo:function(){
		 var store=new Ext.data.SimpleStore({
			 fields:['value','text'],
			 data:[['unit','按单位'],["Sections","按科室"]]
		 });
		 
		 this.statisticModeCbo=new Ext.form.ComboBox({
	    	    fieldLabel:"统计方式",
				triggerAction:'all',
			    displayField:'text',
			    editable:true,
			    valueField:'value',
			    name:'collectType',
			    id:'collectType',
			    store:store,
			    width:80,
			    value:'unit',
			    mode:'local'
	     });	
	},
	//===初始化导出方式Combobx
	initExportModeCbo:function(){
		 var store=new Ext.data.SimpleStore({
			 fields:['value','text'],
			 data:[['1','当前页'],["2","全部页面"]]
		 });
		 
		 this.exportModeCbo=new Ext.form.ComboBox({
	    	    fieldLabel:"导出方式",
				triggerAction:'all',
			    displayField:'text',
			    editable:true,
			    valueField:'value',
			    name:'outMeth',
			    id:'outMeth',
			    store:store,
			    width:80,
			    value:'1',
			    mode:'local'
	     });	
	},
	//---年度的选择改变的时候
	onYearCboSelect:function(combo,record,index){
		
		newValue=parseInt(this.yearCbo.getValue());
		
		//定义一个Record模型
		var MyRecord = Ext.data.Record.create([{name:"key"},{name:"value"} ]);
		//
		var choice=this.dateStatisticsCbo.getValue();
       //获得时间统计类型值
       
	  if(newValue==0){//非0即真

			if(choice!='1'){
					return;
			}
				//1.清空原有的Store中的元素
			 this.statisticTimeCbo.getStore().removeAll();
			   //添加值
			 this.statisticTimeCbo.getStore().add(new MyRecord({key:'0',value:'全部年度'}));
			   //设置默认值
			 this.statisticTimeCbo.setValue('0'); 
	  }else{
         switch(parseInt(choice)){
         case 1://按年统计
        		//1.清空原有的Store中的元素
			 this.statisticTimeCbo.getStore().removeAll();
			   //添加值
			 this.statisticTimeCbo.getStore().add(new MyRecord({key:'-1',value:'本年度'}));
			   //设置默认值
			 this.statisticTimeCbo.setValue('-1'); 
        	 break;
         case 4://按日统计
     		 // 设定日期的值
        	  var startDate=Ext.getCmp('startDate');
        	  var endDate=Ext.getCmp('endDate');
        	  if(!startDate.disabled){//代表该控件现在可用
        		  var d=startDate.getValue();
        		  d.setYear(newValue);
        		  startDate.setValue(d);
        	  }
              if(!endDate.disabled){//代表该控件现在可用
            	  var d=endDate.getValue();
        		  d.setYear(newValue);
        		  endDate.setValue(d);
        	  }
        	 break;
         }
		  
	  }
	},
	//---时间统计类型Cbo更改的时候
	onDateStatisticTypeSelect:function(combo,record,index){
		 var startDate=Ext.getCmp('startDate');
   	     var endDate=Ext.getCmp('endDate');
   	     //得到时间统计类型值
   	     var newValue=parseInt(this.dateStatisticsCbo.getValue());
   	     //combobox显示的默认值
   	     var cboDefaultValue;
		switch(newValue){
				case 4://按日统计
				     //设置日期控件显示
					startDate.setVisible(true);
					endDate.setVisible(true);
					//将disable设置为可用
					startDate.setDisabled(false);
					endDate.setDisabled(false);
					//设定日期控件默认值
					var d=new Date();
					//获得年度Combobox的值
					var year=parseInt(this.yearCbo.getValue());
					if(year!=0){//非0即真
						d.setYear(year);
					 }
					startDate.setValue(d);
					endDate.setValue(d);
					//设定默认值
					cboDefaultValue='0';
					break;
				case 3://按月统计
					//设定默认值
					cboDefaultValue='0';
					break;
				case 2://按季统计
					//设定默认值
					cboDefaultValue='0';
					break;
				case 1://按年统计
					if(this.yearCbo.getValue()=='0'){
						cboDefaultValue='0';
					}else{
						cboDefaultValue='-1';
					}
					break;
		}
		
		//如果不是按日统计那么需要隐藏日期控件
		if(newValue!=4){
			startDate.setVisible(false);
			endDate.setVisible(false);
			startDate.setDisabled(true);
			endDate.setDisabled(true);
		}
		
	    //清空和填充store
		this.fillDateStatisticTypeStore(newValue,cboDefaultValue);
	},
	//---清空原有store中的信息
	//@param newValue是时间统计类型选择项值
	//@param  cboDefaultValue combobox默认值
	fillDateStatisticTypeStore:function(newValue,cboDefaultValue){
		 //定义一个Record模型
 		var MyRecord = Ext.data.Record.create([{name:"key"},{name:"value"} ]);
   	     
		var store=this.statisticTimeCbo.getStore();
		//清空原有的所有元素
		    store.removeAll();
		//添加对应元素
		//添加对应的统计时间
		for(var i=0;i<this.statisticArray[newValue].length;i++ ){
			//得到对应的值
			store.add(new MyRecord(this.statisticArray[newValue][i]));
		}
		//设置默认值
		this.statisticTimeCbo.setValue(cboDefaultValue);
	}
	//---
});

java代码:也就是对应的年度的url

	public String ajaxGetAnnual(){
	    SimpleDateFormat format= new SimpleDateFormat("yyyy");   
        String dateString = format.format(new Date());
        //得到当前的年份
		int year=Integer.parseInt(dateString);
		
		StringBuilder annual=new StringBuilder("[");
		annual.append("{value:'0',year:'全部',selected:false},");
		//
		
        for(int i=0;i<4;i++){
        	if( i == 0)
        	  annual.append("{value:'"+(year-i)+"',year:'"+(year-i)+"',selected:true},");
        	else
              annual.append("{value:'"+(year-i)+"',year:'"+(year-i)+"',selected:false},");
        }
        
        annual=new StringBuilder( annual.substring(0, annual.length()-1));
        
        System.out.println( annual.substring(0, annual.length()-1));
		annual.append("]");
		
		//将年度信息输出
		return ajaxJson(annual.toString());
	}


觉得好就帮忙顶哈...


分享到:
评论

相关推荐

    extJs ComboBox级联

    NULL 博文链接:https://mawj0326-163-com.iteye.com/blog/1628470

    EXTJS的COMBOBOX级联实现和数据提交VALUE[文].pdf

    EXTJS的COMBOBOX级联实现和数据提交VALUE[文].pdf

    extJs4 ComboBox组合框实例

    extJs4 ComboBox 代码组合框实例,ComboBox 各个主要参数详细解释

    ExtJS 设置级联菜单的默认值

    ExtJS在修改这样的页面上赋值是很方便的,在正文中1.2.1代码中可以看出,一行代码就可以搞定,但这是对于普通控件而言,如文本框。对于ComboBox可没这么简单...

    Extjs3.4.0版本 多选下拉框效果支持多选/全选/全不选

    Extjs3.4.0版本 多选下拉框效果支持多选/全选/全不选, 附源码。 修复不能多选问题,代码仅供参考

    Extjs4.0 ComboBox如何实现三级联动

    很多网友在问,Extjs4.0 ComboBox如何实现,好在之前用3.x实现过一个三级联动,如今用Extjs4.0来实现同样的联动效果。其中注意的一点就是,3.x中的model:’local’在Extjs4.0中用queryMode: ‘local’来表示,而且在...

    Extjs4下拉树菜单ComboBoxTree支持单选和多选并且支持展开选中指定节点的通用控件

    Extjs4下拉树菜单 ComboBoxTree 支持单选和多选并且支持展开选中指定节点的通用控件 在项目中已经成熟运用 值得收藏和运用

    EXTJS记事本 当CompositeField遇上RowEditor

    原因是客户的物料种类非常多,有一千种之多,如果单纯用一个Combobox,那么在实际使用中,很难快速找到一个物料,所以,我使用包含物料分类和物料品牌的两个combobox来组成级联式筛选。问题恰恰出在这儿,如果在...

    EXT教程EXT用大量的实例演示Ext实例

    4.4.7. 露一小手,组合上面所知,省市县三级级联。哈哈~ 4.4.7.1. 先做一个模拟的,所有数据都在本地 4.4.7.2. 再做一个有后台的,需要放在服务器上咯 4.5. 把form里的那些控件全部拿出来看看 4.6. form提交数据...

    EXT2.0中文教程

    4.4.7. 露一小手,组合上面所知,省市县三级级联。哈哈~ 4.4.7.1. 先做一个模拟的,所有数据都在本地 4.4.7.2. 再做一个有后台的,需要放在服务器上咯 4.5. 把form里的那些控件全部拿出来看看 4.6. form提交数据的...

    Ext 开发指南 学习资料

    4.4.7. 露一小手,组合上面所知,省市县三级级联。哈哈~ 4.4.7.1. 先做一个模拟的,所有数据都在本地 4.4.7.2. 再做一个有后台的,需要放在服务器上咯 4.5. 把form里的那些控件全部拿出来看看 4.6. form提交数据的...

Global site tag (gtag.js) - Google Analytics