[置顶] ExtJs4.2应用:使用ExtJs扩展组件searchfield实现数据搜索功能
2014-12-08 23:20
936 查看
ExtJs4.2应用:使用ExtJs扩展组件searchfield
实现数据搜索功能
1.引入searchfield组件
在Ext目录下放入ux目录将searchfield组件放入ux目录下的form文件下,如图所示:2.在对应Js文件中引入searchfield组件
dockedItems: [{ dock: 'top', /**在顶部显示*/ xtype: 'toolbar', /**以工具栏形式展示*/ items: { width: "25%", fieldLabel: 'Login Name:', labelWidth:100, xtype: 'searchfield',/**searchfield 是ExtJs的扩展组件 引用路径为Ext.Loader.setPath('Ext.ux', rootPath+'/ux/') 其中rootPath就是Ext类跟路径:比如http://localhost:8080/demo/Ext */ store: store /**对应的数据集*/ } },{ xtype: 'pagingtoolbar', store: store, dock: 'bottom', displayInfo: true }]
3.完整的JS代码
Ext.Loader.setConfig({enabled: true});
Ext.Loader.setPath('Ext.ux', rootPath+'/ux/');
Ext.require([
'Ext.ux.form.SearchField'
]);
var itemsPerPage = 15;
var params;
var store = Ext.create('Ext.data.Store',{
fields:["id","firstName","lastName","loginName","telephone","brithday","sexId","depId"],
proxy:{
type:'ajax',
url:'/demo/JobData.action',
reader:{
type:'json',
root:'rootData',
totalProperty: 'totalCount'
}
},
pageSize: itemsPerPage,
autoLoad:true
});
Ext.onReady(function(){
Ext.Loader.setConfig({
enabled:true
});
Ext.create('Ext.grid.Panel',{
title:'Job Enquiry',
width:'100%',
layout:"auto",
style:"margin-left:auto;margin-right:auto;",
renderTo:Ext.getBody(),
columns:[{
header:'Id',
flex: 1,align:"center",
dataIndex:'id',
sortable:true
},{
header : "First Name",
flex: 1, align:"center",
dataIndex : 'firstName',
sortable : true
}, {
header : "Last Name",
flex: 1, align:"center",
dataIndex : 'lastName',
sortable : true
}, {
header : "Login Name",
flex: 1,
align:"center",
dataIndex : 'loginName',
sortable : true
}, {
header : "Telephone",
flex: 1,align:"center",
hideable: false,
dataIndex : 'telephone',
sortable : true
}, {
header : "brithday",
flex: 1, align:"center",
dataIndex : 'brithday',
sortable : true
}, {
header : "Sex Id",
flex: 1, align:"center",
dataIndex : 'sexId',
sortable : true
}, {
header : "Dep Id",
flex: 1, align:"center",
dataIndex : 'depId',
sortable : true
}],
store:store,
//style:"margin-left:auto;margin-right:auto;align:center",
pageSize: itemsPerPage,
dockedItems: [{ dock: 'top', /**在顶部显示*/ xtype: 'toolbar', /**以工具栏形式展示*/ items: { width: "25%", fieldLabel: 'Login Name:', labelWidth:100, xtype: 'searchfield',/**searchfield 是ExtJs的扩展组件 引用路径为Ext.Loader.setPath('Ext.ux', rootPath+'/ux/') 其中rootPath就是Ext类跟路径:比如http://localhost:8080/demo/Ext */ store: store /**对应的数据集*/ } },{ xtype: 'pagingtoolbar', store: store, dock: 'bottom', displayInfo: true }]
});
store.load({params:{start:0,limit:itemsPerPage}});
var startTime;
var endTime;
function checkDate(){
startTime = Ext.getCmp("startTime");
endTime = Ext.getCmp("endTime");
if(startTime != null && endTime != null && startTime.getValue() > endTime.getValue()){
alert("Start time must be smaller than the end time!");
return false;
}
return true;
}
function query(){
//check date
if(!checkDate()){
return ;
}
params = {
'conEnquiryTicketVo.startTime':startTime.getValue(),
'conEnquiryTicketVo.endTime':endTime.getValue(),
start:0,
limit:itemsPerPage
};
// store.on('beforeload',function(){
// var startTime = Ext.getCmp("startTime");
// var endTime = Ext.getCmp("endTime");
// //alert("click!!"+startTime.getValue());
// params = {
// 'conEnquiryTicketVo.startTime':startTime.getValue(),
// 'conEnquiryTicketVo.endTime':endTime.getValue(),
// start:0,
// limit:itemsPerPage
// };
// });
store.load({params:params});
}
});
4.效果图
对应的Java代码在上一篇:
ExtJs4.2应用:ExtJs4.2+Mysql+Struts2+Hibernate3实现分页查询
基础上将GetJobDataAction.java内容修改为:
package com.qiuzhping.report.action; import java.math.BigDecimal; import java.util.List; import org.apache.log4j.Logger; import com.opensymphony.xwork2.ActionSupport; import com.qiuzhping.report.dao.impl.DepartmentDaoImpl; import com.qiuzhping.report.domian.Job; /** * <Description functions in a word> * <Detail description> * * @author Qiuzhenping * @version [Version NO, 2014-12-5] * @see [Related classes/methods] * @since [product/module version] */ public class GetJobDataAction extends ActionSupport{ /** *serialVersionUID */ private static final long serialVersionUID = 3288957476157165689L; private Logger log = Logger.getLogger(this.getClass()); private BigDecimal totalCount; private List rootData; private int start; private int limit; private String query;<span><span class="comment">/**query字段对应的是扩展组件searchfield的名字,详细的可以查看searchfield的源码*/</span><span></span></span> public String getQuery() { return query; } public void setQuery(String query) { this.query = query; } public BigDecimal getTotalCount() { return totalCount; } public void setTotalCount(BigDecimal totalCount) { this.totalCount = totalCount; } public List getRootData() { return rootData; } public void setRootData(List rootData) { this.rootData = rootData; } public int getStart() { return start; } public void setStart(int start) { this.start = start; } public int getLimit() { return limit; } public void setLimit(int limit) { this.limit = limit; } @Override public String execute(){ try { DepartmentDaoImpl ddi = new DepartmentDaoImpl(); log.info("start = "+start); log.info("limit = "+limit); int end = start+limit; log.info("end = "+end); totalCount = ddi.getTotalCount(Job.class,query); rootData = ddi.getData(start, limit,Job.class,query); } catch (Exception e) { log.error(e); } return SUCCESS; } }
DepartmentDaoImpl.java内容修改为:
package com.qiuzhping.report.dao.impl; import java.lang.reflect.Field; import java.math.BigDecimal; import java.sql.SQLException; import java.sql.Timestamp; import java.util.List; import org.hibernate.HibernateException; import org.hibernate.SQLQuery; import org.hibernate.Session; import org.hibernate.Transaction; import com.qiuzhping.report.domian.Job; import com.qiuzhping.report.util.HibernateSessionFactory; /** * <Description functions in a word> * <Detail description> * * @author Qiuzhenping * @version [Version NO, 2014-12-5] * @see [Related classes/methods] * @since [product/module version] */ public class DepartmentDaoImpl{ private HibernateSessionFactory hsf = HibernateSessionFactory.getInstance(); public BigDecimal getTotalCount(Class clazz,String name){ Session session = hsf.getSessionFactory().openSession(); StringBuffer sql = new StringBuffer("SELECT * FROM job "); if(name != null){ sql.append(" WHERE loginName like '%"+name+"%' "); } SQLQuery query =session.createSQLQuery(sql.toString()); query.addEntity(clazz); return new BigDecimal(query.list().size()); } public List<Job> getData(int start,int end,Class clazz,String name){ Session session = hsf.getSessionFactory().openSession(); StringBuffer sql = new StringBuffer("SELECT * FROM job"); if(name != null){ sql.append(" WHERE loginName like '%"+name+"%' "); } sql.append(" LIMIT "+start+","+end); SQLQuery query =session.createSQLQuery(sql.toString()); query.addEntity(clazz); return query.list(); } public void save() throws HibernateException, SQLException{ Session session = hsf.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); for (int i = 0; i < 1000; i++) { Job job = new Job(); job.setId(i + 10); job.setBrithday(new Timestamp(System.currentTimeMillis())); job.setSexId(0); job.setLoginName("qiuzhping"+i); job.setLastName("qiuzhping"+i); job.setFirstName("qiu"+i); job.setDepId(1); session.saveOrUpdate(job); if (i % 20 == 0) { // 单次批量操作的数目为20 session.flush(); // 清理缓存,执行批量插入20条记录的SQL insert语句 session.clear(); // 清空缓存中的Customer对象 } } tx.commit(); session.close(); } /** <Description functions in a word> * * <Detail description> * @author Qiuzhenping * @param args [Parameters description] * @return void [Return type description] * @throws SQLException * @throws HibernateException * @exception throws [Exception] [Exception description] * @see [Related classes#Related methods#Related properties] */ public static void main(String[] args) throws HibernateException, SQLException { //DepartmentDaoImpl ddi = new DepartmentDaoImpl(); //ddi.save(); //System.out.println(ddi.getData(0, 25,Job.class).size()); Field[] fields = Job.class.getDeclaredFields(); for(Field f :fields){ System.out.print("\""+f.getName()+"\","); } } }
转摘请注明:http://blog.csdn.net/qiuzhping/article/details/41811655
ExtJs4.2序列笔记
ExtJs4.2应用:ExtJs4.2+Mysql+Struts2+Hibernate3实现分页查询
ExtJs4.2应用:使用ExtJs扩展组件searchfield实现数据搜索功能
相关文章推荐
- 在 Laravel 中使用 Laravel Searchy 扩展包实现基于数据库的轻量级搜索功能
- Flex中Tree组件实现导航树搜索定位功能及Tree组件的的使用要点
- 使用DataList和SQL2005实现分页显示数据(应用举例:站内简单搜索)
- 使用ExtJs 来显示数据,并实现数据的分页功能
- EXTJS4 Grid Filter 插件的使用 与后台数据解析------Extjs 查询筛选功能的实现
- [置顶] ExtJs4.2应用:ExtJs4.2+Mysql+Struts2+Hibernate3实现分页查询
- ThinkPHP使用getlist方法实现数据搜索功能示例
- yii2高级应用之自定义组件实现全局使用图片上传功能的方法
- 在 Laravel 中使用 Laravel Searchy 扩展包实现基于数据库的轻量级搜索功能
- 关于ligerui 中 grid 表格的扩展搜索功能在远程数据加载时无法使用的解决办法
- 通过使用第三方SDK来实现应用的分享,第三方登陆,数据信息统计等功能(ShareSDK)。
- 深入剖析ExtJS 2.2实现及应用连载(13):数据与列表的应用
- C#使用XmlEDocument实现数据文件安全存储功能
- 使用silverlight构建一个工作流设计器(十八)-持久化数据到数据库—服务器段功能实现
- 使用ajaxToolkit组件实现类型google,百度下拉框匹配功能
- ExtJs是通过Ext.ToolTip和Ext.QuickTips两个组件来实现浮动提示功能的
- 图片上传功能的实现(FileUpload组件的使用)
- 扩展UltraGrid控件实现对所有数据行的全选功能[Source Code下载]
- 使用ADF组件实现附件上传下载功能
- 使用UI Automation实现自动化测试--7.1 (模拟键盘输入数据在自动化测试中的应用)