`

Extjs grid工具栏中搜索的实现

阅读更多

Extjs grid工具栏中搜索的实现

 

1.单选框+文本框:

{
	id:"byXmmc",
	xtype:"radio",
	boxLabel:"按项目名称 ",
	name:"ftype",  //注意两个radio的name是一样的,才是一组的
	listeners:{
		"check":function(){
			Ext.getCmp("paras").setValue("");//文本框置空
		}
	}
},{
	id:"byQymc",
	xtype:"radio",
	boxLabel:"按企业名称 ",
	name:"ftype",
	checked:true  //默认选中
},{
	id:"paras",
	xtype:"textfield",
	enableKeyEvent:true,//开启文本框按键监听
	listeners:{
		"specialKey":function(f,e){  //注意这里是2个参数!
			if(e.getKey() == e.ENTER){  //或:e.getKey()==Ext.EventObject.ENTER
				var field = "qymc";
				if(Ext.getCmp("byXmmc").checked){
					field = "xmmc";
				}
				var paras = Ext.getCmp("paras").getValue();
				var status = Ext.getCmp("status").getValue();
				epStore.baseParams.pField = field;
				epStore.baseParams.pParas = paras;
				epStore.baseParams.pStatus = status;
				epStore.load({params:{start:0,limit:pageSize}});
			}
		}
	}
}

   
 

2.Combox下拉选框:

{
	xtype:"label",
	text:"状态:"
},{
	id:"status",
	xtype:"combo",
	value:'', 
    width:90,
    mode : 'local', 
    triggerAction :'all', 
    forceSelection:true, //强制选择
    store : new Ext.data.SimpleStore({ 
    	fields : ["id", "name"], 
    	data : [ 
			['', '全部'],     
        	['0', '等待审核'], 
        	['1', '审核成功']
     	] 
	}),
    valueField : "id", 
    displayField : "name", 
    readOnly: true  //不可输入
}

 

3.搜索按钮:

{
	text: '搜索',
	iconCls: 'filter',
	listeners:{
		"click":function(){
			var field = "qymc";
			if(Ext.getCmp("byXmmc").checked){
				field = "xmmc";
			}
			var paras = Ext.getCmp("paras").getValue();
			var status = Ext.getCmp("status").getValue();
			epStore.baseParams.pField = field;
			epStore.baseParams.pParas = paras;
			epStore.baseParams.pStatus = status;
			epStore.load({params:{start:0,limit:pageSize}});
		}
	}
}

 

 

综合示例:

1.Extjs:

/*-----1.创建数据源-----*/
var epStore = new Ext.data.JsonStore({
	autoLoad: true,
	url:"getEProject.eva?doType=getAuditProject",
	root:"data",
	fields: ["id","xmid","project","company","etype","emode","eagency","status","advice","audit_date","other"]
});


/*-----2.创建视图渲染颜色-----*/
var epView = new Ext.grid.GridView({
	getRowClass : function(record, rowIndex){
		if(record.get('status') == 1){
			return "readOnly";
		}
	}
});


/*-----3.创建ColumnModel-----*/
var sm = new Ext.grid.CheckboxSelectionModel();
var cm = new Ext.grid.ColumnModel({
	columns:[
		sm,
		{
			header:"编号",
			dataIndex:"id",
			hidden:true
		},{
			header:"项目名称",
			dataIndex:"project",
			width:150,
			sortable:true
		},
		......
		...
		...
	]
});

/*-----4.创建表格面板-----*/
var grid = new Ext.grid.GridPanel({
	store:epStore,
	cm:cm,
	sm:sm,
	view: epView,
	loadMask:{msg:'正在加载数据,请稍侯……'},  
	height:80,
	tbar:[
		{
			id:"byXmmc",
			xtype:"radio",
			boxLabel:"按项目名称 ",
			name:"ftype",
			listeners:{
				"check":function(){
					Ext.getCmp("paras").setValue("");
				}
			}
		},{
			id:"byQymc",
			xtype:"radio",
			boxLabel:"按企业名称 ",
			name:"ftype",
			checked:true
		},{
			id:"paras",
			xtype:"textfield",
			enableKeyEvent:true,
			listeners:{
				"specialKey":function(f,e){
					if(e.getKey() == e.ENTER){
						var field = "qymc";
						if(Ext.getCmp("byXmmc").checked){
							field = "xmmc";
						}
						var paras = Ext.getCmp("paras").getValue();
						var status = Ext.getCmp("status").getValue();
						epStore.baseParams.pField = field;
						epStore.baseParams.pParas = paras;
						epStore.baseParams.pStatus = status;
						epStore.load({params:{start:0,limit:pageSize}});
					}
				}
			}
		},"-",{
			xtype:"label",
			text:"状态:"
		},{
			id:"status",
			xtype:"combo",
			value:'', 
	        width:90,
	        mode : 'local', 
	        triggerAction :'all', 
	        forceSelection:true,
	        store : new Ext.data.SimpleStore({ 
	        	fields : ["id", "name"], 
	        	data : [ 
					['', '全部'],     
		        	['0', '等待审核'], 
		        	['1', '审核成功']
	         	] 
        	}),
	        valueField : "id", 
	        displayField : "name", 
	        readOnly: true
		},"-",{
			text: '搜索',
        	iconCls: 'filter',
        	listeners:{
        		"click":function(){
        			var field = "qymc";
					if(Ext.getCmp("byXmmc").checked){
						field = "xmmc";
					}
					var paras = Ext.getCmp("paras").getValue();
					var status = Ext.getCmp("status").getValue();
					epStore.baseParams.pField = field;
					epStore.baseParams.pParas = paras;
					epStore.baseParams.pStatus = status;
					epStore.load({params:{start:0,limit:pageSize}});
        		}
        	}
		},{
			text:"审核项目",
			iconCls: 'audit',
			handler:showAuditWin
		},{
			text:"查看审核详情",
			iconCls:"apply",
			icon: '../images/apply.gif',
			handler:showAuditDetailWin
		}
	],
	bbar: new Ext.PagingToolbar({
        pageSize: pageSize,
        store: epStore,
        displayInfo: true,
        displayMsg: '当前显示 {0} - {1} ,共{2}条记录',
        emptyMsg: "没有数据",
        items: ['-']
    })
});

 

2.Servlet:

if ("getAuditProject".equals(action)) {
	String pField = request.getParameter("pField");
	String pParas = request.getParameter("pParas");
	String pStatus = request.getParameter("pStatus");
	EvaluationDao evaluationDao = new EvaluationDao();
	JSONObject jObject = new JSONObject();
	jObject.put("data", evaluationDao.getAuditProject(user,pField,pParas,pStatus));
	response.setContentType("text/json;charset=UTF-8");
	out = response.getWriter();
	out.print(jObject);
	out.close();
	return;
}

 

3.Dao:

public JSONArray getAuditProject(User user, String field, String paras, String status) {
	Session s = null;
	List list = null;
	JSONArray jArray = new JSONArray();
	long did = Long.valueOf(user.getDepartment().getDid());
	try {
		s = HibernateUtil.getSession();
		s.beginTransaction();
		StringBuffer sb = new StringBuffer();
		if (user.getUserid().equals("admin")) {
			sb.append("select au.id,p.xmid,p.xmmc,"
					+ "e.qymc,ev.etype,ev.emode,ev.eagency,au.status,au.advice,au.audit_date from "
					+ "enterprise e,en_project p,project_evaluate ev,"
					+ "project_audit au where e.swdjzh = p.swdjzh and "
					+ "p.xmid in ev.xmid and au.jid = ev.id");
		}
		else {
			sb.append("select au.id,p.xmid,p.xmmc,"
					+ "e.qymc,ev.etype,ev.emode,ev.eagency,au.status,au.advice,au.audit_date from "
					+ "enterprise e,en_project p,project_evaluate ev,"
					+ "project_audit au where e.swdjzh = p.swdjzh and "
					+ "p.xmid in ev.xmid and au.jid = ev.id and au.did =" + did);
		}
		if (paras != null && !"".equals(paras)) {
			if ("xmmc".equals(field)) {
				sb.append(" and p.xmmc like '%"+paras+"%' ");
			}else if ("qymc".equals(field)) {
				sb.append(" and e.qymc like '%"+paras+"%' ");
			}
		}
		if(status != null && !"".equals(status)){
			sb.append(" and au.status = " + status);
		}
		Query query = s.createSQLQuery(sb.toString());
		list = query.list();
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				Object[] obj = (Object[]) list.get(i);
				JSONObject jObject = new JSONObject();
				jObject.put("id", obj[0]);
				jObject.put("xmid", obj[1]);
				jObject.put("project", obj[2]);
				jObject.put("company", obj[3]);
				jObject.put("etype", obj[4]);
				jObject.put("emode", obj[5]);
				jObject.put("eagency", obj[6]);
				jObject.put("status", obj[7]);
				jObject.put("advice", obj[8]);
				jObject.put("audit_date", obj[9]);
				jArray.put(jObject);
			}
		}
	} catch (Throwable e) {
		logger.error(e);
		HibernateUtil.endSession(s);
	} finally {
		HibernateUtil.endSession(s);
	}
	return jArray;
}

 

图示:

 

 

 

 

 

  • 大小: 3.2 KB
  • 大小: 2.4 KB
  • 大小: 8.8 KB
  • 大小: 9.5 KB
  • 大小: 23.8 KB
分享到:
评论

相关推荐

    extjs-grid-searching:ExtJS网格工具栏扩展添加了搜索功能

    extjs-grid-searching ExtJS网格工具栏扩展添加了搜索功能。

    ExtJS 4.2 Grid组件单元格合并的方法

    从这些代码中可以看出,Grid组件可分为grid-header和grid-body 两块区域(若含有工具栏和分页栏,它们都会含有各自的独立区域)。 其中grid-body包含了许多tr元素,每一个tr都是代表Grid组件中的一行数据;每个tr内部...

    ExtJs+Dwr带分页分组传参后台排序功能的grid

    Service类(RecordServiceImpl),Service接口(RecordService),分页类(ListRange.java),dwr自带(engine.js),ext自带(ext-all.js,ext-base.js,ext-all.css),(分页底部工具栏)PagingToolbar.js

    Extjs4.1.1

    第三讲.ExtJS工具栏、菜单栏 第四讲.ExtJS最常用的表单之textfield控件 第五讲.ExtJs最常用表单组件Number、CheckBox、Radio 第六讲.ExtJs最常用表单组件ComboBox、time、date 第七讲.ExtJS面板Panel 第八讲....

    extjs 学习笔记 四 带分页的grid

    在extjs中,类Ext.PagingToolbar封装了关于分页的操作,该类从Toolbar继承而来,单从名字上看,我们也猜得出这是一个能够处理分页的工具栏。好吧,那我们就来看看如何构造这样一个工具栏吧。PagingToolbar类的构造...

    深入浅出Extjs4.1.1

    3、ExtJS工具栏、菜单栏0 Q' y0 E. y E 4、ExtJS最常用的表单之textfield控件4 |4 ]8 ~/ d3 Y& k# X 5、ExtJs最常用表单组件Number、CheckBox、Radio* s, r% ~+ k; y# W 6、ExtJs最常用表单组件ComboBox、time、date...

    精通JS脚本之ExtJS框架.part2.rar

    本书共分17章,分别介绍了JavaScript的对象编程、JavaScript浏览器对象模型和事件机制、ExtJS的核心类库和组件、ExtJS的事件处理方式、设计进度条、设计工具栏和菜单栏、设计面板、设计表格、设计表单、设计数据表、...

    jq-extgrid v1.2 表格插件

    http: www extgrid com extgrid 是一款jquery上的gird插件 界面风格采用了类似easyui extjs 界面风格样式 可通过...extgrid具有列大小 位置改变 排序 分组 分页 工具栏 扩展行 rowNumber 多选列 编辑列 行列 [更多]

    深入浅出ExtJS第2版

    3.9.3 分页工具栏显示在Grid的顶部 51 3.9.4 让EXT支持前台排序 52 3.10 后台排序 53 3.11 可编辑表格控件--EditorGrid 55 3.11.1 制作一个简单的EditorGrid 55 3.11.2 添加一行数据 56 3.11.3 保存修改结果 ...

    ExtJs详细介绍

    ExtJs的详细介绍, 第一章 起步 第二章 Ext概览 第三章 表单 第四章 按钮、菜单和工具栏 第五章 使用grid显示数据 第六章 Editor Grids(可编辑表格) 第七章 layout(布局) 第八章 Tree(树)

    ExtJSWeb应用程序开发指南(第2版)

    3.4 实现工具栏和菜单栏 3.4.1 认识Ext.toolbar.Toolbar 3.4.2 只包含按钮的简单工具栏 3.4.3 包含多种元素的复杂工具栏 3.4.4 启用和禁用工具栏 3.4.5 认识Ext.menu.Menu菜单 3.4.6 最简单的菜单栏 3.4.7 ...

    轻松搞定Extjs_原创

    二、分页工具栏 154 三、分页 154 四、小结 157 第二十二章:GridPanel扩展 158 一、学会自学吧,朋友 158 二、带摘要的GridPanel 158 三、RowExpander 162 四、分组GridPanel 165 五、将带摘要的GridPanel和分组...

    精通JS脚本之ExtJS框架.part1.rar

    本书共分17章,分别介绍了JavaScript的对象编程、JavaScript浏览器对象模型和事件机制、ExtJS的核心类库和组件、ExtJS的事件处理方式、设计进度条、设计工具栏和菜单栏、设计面板、设计表格、设计表单、设计数据表、...

    EXTJS 学习笔片段1

    EXTJS 学习笔片段1 Form ComboBox ... 分页工具栏创建 Window 弹出处理window窗口(模态窗口) MessageBox show(报错窗口、保存提示、选择窗口) alert prompt 实用工具类 JS异常捕捉 Ajax提交

    ExtJs教程_完整版

    Ext 2.x版本,一共8章: 第一章 起步 第二章 Ext概览 第三章 表单 第四章 按钮、菜单和工具栏 第五章 使用grid显示数据 第六章 Editor Grids(可编辑表格) 第七章 layout(布局) 第八章 Tree(树)

    extjs-reactjs-examples:ExtJS到React过渡的代码示例

    工具栏(代码) 面板(代码) 标签面板(代码) 轮播(代码) 浮动组件(代码) 数据绑定/控制器 用React绑定(代码) 使用Redux处理应用程序状态(代码) 使用MobX处理应用程序状态(代码) 资料储存库 ...

    Ext Js权威指南(.zip.001

    1.4.2 在visual studio中实现智能提示 / 23 1.4.3 spket / 28 1.4.4 在eclipse中实现智能提示 / 32 1.5 如何获得帮助 / 32 1.6 本章小结 / 33 .第2章 从“hello world”开始 / 34 2.1 获取ext js 4 / 34 2.2...

    ExtAspNet_v2.3.2_dll

    -Grid中TemplateField生成到页面中控件具有唯一ID,例如Grid1_ct5_Label2,Grid1_ct6_Label2(feedback:geruger)。 +2009-09-27 v2.1.2 -为Tree控件增加GetExpandAllNodesReference和...

    ExtAspNet v2.2.1 (2009-4-1) 值得一看

    -Grid中TemplateField生成到页面中控件具有唯一ID,例如Grid1_ct5_Label2,Grid1_ct6_Label2(feedback:geruger)。 +2009-09-27 v2.1.2 -为Tree控件增加GetExpandAllNodesReference和...

    FineUI(ASP.NET UI控件) v4.1.3.rar

    FineUI(开源版) 基于 ExtJS 的开源 ASP.NET 控件库。...增加示例:导航控件-&gt;工具栏与菜单-&gt;内联菜单(HideOnClick)。 表格的PageIndex有效性检查,更新示例:表格控件-&gt;分页工具条-&gt;改变每页记录数。

Global site tag (gtag.js) - Google Analytics