具體代碼如下:
引用js和css文件有:
代碼如下:
<link ID="skin" rel="stylesheet" type="text/css" href="css/config.css">
<script type="text/javascript" src="js/config.js"></script>
<script type="text/javascript" src="js/skin.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.table.js"></script>
頁面代碼:
代碼如下:
<table id="userTable" align="center" class="listtable" width="100%" bgcolor="#CCCCCC" cellSpacing="1" cellpadding="1" style="margin-top:5px;" >
<thead>
<tr class="fixheader">
<td noWrap width="5%">選擇</td>
<td noWrap width="10%">用戶ID<img src="images/up.png" style= "cursor:hand " alt="升序" align="absmiddle"><img src="images/down.png" style= "cursor:hand " alt="降序"align="absmiddle"></td>
<td noWrap width="10%">用戶名稱<img src="images/up.png" style= "cursor:hand " alt="升序" align="absmiddle"><img src="images/down.png" style= "cursor:hand " alt="降序"align="absmiddle"></td>
<td noWrap width="10%">所在科室<img src="images/up.png" style= "cursor:hand " alt="升序" align="absmiddle"><img src="images/down.png" style= "cursor:hand " alt="降序"align="absmiddle"></td>
<td width="10%" noWrap>創建時間<img src="images/up.png" style= "cursor:hand " alt="升序" align="absmiddle"><img src="images/down.png" style= "cursor:hand " alt="降序"align="absmiddle"></td>
<td width="10%" noWrap>創建人<img src="images/up.png" style= "cursor:hand " alt="升序" align="absmiddle"><img src="images/down.png" style= "cursor:hand " alt="降序"align="absmiddle"></td>
<td width="10%" noWrap>菜單集名稱<img src="images/up.png" style= "cursor:hand " alt="升序" align="absmiddle"><img src="images/down.png" style= "cursor:hand " alt="降序"align="absmiddle"></td>
<td width="10%" noWrap>是否有效<img src="images/up.png" style= "cursor:hand " alt="升序" align="absmiddle"><img src="images/down.png" style= "cursor:hand " alt="降序"align="absmiddle"></td>
</tr>
</thead>
<tbody style="display:">
<c:forEach items="${userList}" var="smUser">
<tr height="22px" bgcolor="#F9FDFF" onmouseover="javascript:this.style.backgroundColor='#FFFFCC'; return true;" onMouseOut="javascript:this.style.backgroundColor='#F9FDFF'; return true;">
<td align="center"><input type="checkbox"></td>
<td class="tdc">${smUser.userId }</td>
<td class="tdc">${smUser.userName }</td>
<td class="tdc">${smUser.organCode }</td>
<td class="tdc">${smUser.createTime }</td>
<td class="tdc">${smUser.creator }</td>
<td class="tdc">${smUser.menusId }</td>
<td class="tdc">${smUser.valid }</td>
</tr>
</c:forEach>
</tbody>
</table>
<script language="javascript" type="text/javascript">
$("#userTable").tablePaging();
</script>
此處要特別注意的是要講table的表頭加上<thread></thread>標簽,且注意此處的table的id為userTable,這個在後面Js文件的引用中十分重要,一句$("#userTable").tablePaging();會去執行jquery.table.js中的代碼。
後台action的代碼如下:
代碼如下:
public ActionForward listUser(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
List<POJO> pojos = serviceSmUserImpl.findAll();
List<SmUser> smUserList = new ArrayList<SmUser>();
for(POJO pojo:pojos){
smUserList.add((SmUser)pojo);
}
request.setAttribute("userList",smUserList);
return mapping.findForward("smUserList");
}
運用jquery實現表格分頁打包