



下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、Grid中實現分頁查詢注:將Tomcat 5.0下的conf/server.xml中的URIEncoding 設置成UTF-8可以解決中文問題1、導入文件:<link rel="STYLESHEET" type="text/css" href="././codebase/dhtmlxgrid.css"><link rel="STYLESHEET" type="text/css" href="././codebase/ext/dhtmlxgrid_pgn_bricks.
2、css"><script src="././codebase/dhtmlxcommon.js"></script><script src="././codebase/dhtmlxgrid.js"></script><script src="././codebase/ext/dhtmlxgrid_pgn.js"></script><script src="././codebase/dhtmlxgridcell.js">
3、</script>2、jsp頁中的相關設置/兩個input域 和一個button按鈕用于模糊查詢<div>Name<br><input type="text" id="search_name"></div><div>Chname<br><input type="text" id="search_chname"><button onclick="reloadGrid()" id="sub
4、mitButton" style="margin-left:30px;">Search</button></div><div id="gridbox" style="width:100%;height:200px;margin-top:20px;margin-bottom:10px;"></div><div><span id="pagingArea"></span></div>3、初始化:<scri
5、pt>function doOnLoad()var mygrid = new dhtmlXGridObject('gridbox');mygrid.setImagePath("././codebase/imgs/");mygrid.setHeader("id,name,chname,pwd");mygrid.setInitWidths("150,150,*,150")mygrid.setColAlign("left,left,left,right")mygrid.setColSorting(&
6、quot;server,na,na,server");mygrid.setColTypes("ro,ro,ro,ro");mygrid.setSkin("light");mygrid.init();/mygrid.enablePaging(true,10,5,"pagingArea",true);mygrid.setPagingSkin("bricks");/mygrid.loadXML("./././user!mylist.action");</script>/enabl
7、ePaging中對應的參數的意義分別是:是否開啟分頁;每頁顯示的行數(這里設置為10行);每次顯示多少頁(下圖為顯示5頁);分頁div的id;是否顯示統計結果(對應下圖的 Records from 1 to 10 of 999)/模糊插敘方法function reloadGrid()var name_mask = document.getElementById("search_name").valuevar chname_mask = document.getElementById("search_chname").value/把查詢條件傳到action
8、中mygrid.clearAndLoad("<%=basePath%>user!mylist.action?name_mask="+name_mask+"&chname_mask="+chname_mask);4、后臺action/得到posStart(從那條數據開始讀)count(讀取多少條數據)和兩個查詢條件String count = req.getParameter("count");String posStart = req.getParameter("posStart");Strin
9、g name = req.getParameter("name_mask");String chname = req.getParameter("chname_mask");/第一次請求posStart和count值均為空,需要一個默認值int icount=50;/默認第一次取出50條記錄try icount =Integer.parseInt(count); catch (Exception e) if(null=count)icount = 50;int iposStart=0;try iposStart = Integer.parseInt(po
10、sStart); catch (Exception e) if(null=posStart)iposStart = 0;/統計數據的總條數(在這里直接得到一個list,然后conntlist.size取得的)對應xml文、/件中的total_count的值List conntlist = baseService.queryByHqlName("queryPage",map);/定義一個Map,將查詢條件put到map中Map map = new HashMap();if (name=null) name=""if (chname=null) chname
11、=""map.put("nameP","%"+name+"%");map.put("chnameP","%"+chname+"%");/ 通過調用BaseDaoImpl中類的loadPageData方法進行分頁查詢,得到一個list/參數"queryPage"為user-query.hbm.xml中的name(就是下面的代碼)list = baseService.loadPageData(iposStart,icount,UserFor
12、m.class,"queryPage",map);5、user-query.hbm.xml配置文件<query name="queryPage">from UserForm where 1=1and name like :namePand chname like :chnameP</query>6、xml文件格式 (這個例子用到了數據庫中users表)/ total_count為數據總行數;pos為起始行<?xml version="1.0" encoding="UTF-8"?><rows total_count='conntlist.size()' pos='iposStart'
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
評論
0/150
提交評論