標籤:
要求:在easyui-datagrid中完成paginaton的分頁功能。
1.easyui-datagrig的配置
<table id="dg" rownumbers=true fitColumns="true" singleSelect="true"data-options="pagination:true,fit:true,toolbar:‘#tt‘"><thead><tr><th field="bNo" align="center" width="120px">櫃員號</th><th field="bType" align="center" width="150px">櫃員類型</th><th field="jGNo" align="center" width="120px">機構號</th><th field="pZCount" align="center" width="120px">憑證數</th><th field="zJcount" align="center" width="120px">主件數</th><th field="fJcount" align="center" width="120px">附件數</th><th field="sBPass" align="center" width="150px">識別憑證</th><th field="sBSuccess" align="center" width="150px">識別成功</th><th field="sBRoute" align="center" width="120px">識別率</th><th field="yWDate" align="center" width="170px">業務日期</th></tr></thead></table>
pagination="true"資料表格會自動將分頁欄置於表下方;toolbar="#tt"表示為資料表格上方加入工具列,具體樣式是id="#tt"的模組決定的。在看下js檔案對datagrid的其他配置:
$(‘#dg‘).datagrid({url:‘user/queryList.action‘,pageList: [5,10,20,50,100], pageSize:5});
url為頁面重新整理datagrid自動的請求,每次請求會向後台傳入兩個參數:1)page,當前第幾頁;2)rows,每頁顯示幾條資料。因此在後台需要就收這兩條重要訊息。
2.struts2的Action配置
public String queryList(){List<User> list = userService.queryList(page,rows) ;pag1 = new Pagination<User>();pag1.setTotal(userService.getCount());pag1.setRows(list);return SUCCESS ;}
<package name="work" namespace="/user" extends="json-default,struts-default"><action name="queryList" class="userAction" method="queryList"><result type="json"><param name="root">pag1</param></result></action>
</package>
pag1為DTO資料轉送對象,有total和rows兩屬性(datagrid要求的json格式)
3.hibernate層service分頁方法
public List<User> queryList(int page, int pageSize) {// TODO Auto-generated method stubString hql = "from User";Query query = userDao.getSession().createQuery(hql);int beginNum = (page-1)*pageSize;int endNum = beginNum+pageSize>getCount()?getCount()-beginNum :pageSize ;query.setMaxResults(endNum); query.setFirstResult(beginNum); return query.list();}
基於SSH架構、Oracle資料庫、easyui的分頁顯示