jquery.pagination.js分頁使用教程

這篇文章主要爲大家詳細介紹了jquery.pagination.js分頁使用教程,具有一定的參考價值,感興趣的小夥伴們可以參考一下

簡單介紹一下在動態網頁裏面的jquery.pagination.js分頁的使用,具體內容如下

添加下載的js和樣式,主要是先添加jquery.js 再添加jquery.pagination.js,我這是下載好的,放在本地

<link rel="stylesheet" href="<%=path%>css/pagination.css" type="text/css">
<script type="text/javascript" src="<%=path%>js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="<%=path%>js/jquery.pagination.js"></script>

表格,用的是c標籤,獲取控制器傳過來的值

<table width="1052" border=0 align=center cellpadding=2 cellspacing=1
   bordercolor="#799AE1" class=tableBorder>
   <tbody>
    <tr>
     <th align=center colspan=16 style="height: 23px">商品顯示</th>
    </tr>

    <tr align="center" bgcolor="#799AE1" style="height:28px">
     <td width="10%" align="center" class=txlHeaderBackgroundAlternate>商品編號</td>
     <td width="10%" align="center" class=txlHeaderBackgroundAlternate>商品大類</td>
     <td width="10%" align="center" class=txlHeaderBackgroundAlternate>商品名稱</td>
     <td width="10%" align="center" class=txlHeaderBackgroundAlternate>商品規格</td>
     <td width="10%" align="center" class=txlHeaderBackgroundAlternate>加權進價</td>
     <td width="10%" align="center" class=txlHeaderBackgroundAlternate>當前售價</td>
     <td width="10%" align="center" class=txlHeaderBackgroundAlternate>操作</td>

    </tr>


    <c:forEach items="${goodsS}" var="goods">
     <tr bgcolor="#DEE5FA">
      <td align="center" id="goodsId" class="txlrow"><c:out
        value="${goods.goodsId}"></c:out></td>
      <td align=center id="goodsType" class=txlrow><c:out
        value="${goods.goodsType}"></c:out></td>
      <td align=center id="goodsName" class=txlrow><c:out
        value="${goods.goodsName}"></c:out></td>
      <td align=center id="goodsContent" class=txlrow><c:out
        value="${goods.goodsContent}"></c:out></td>
      <td align=center id="goodsPrice" class=txlrow><c:out
        value="${goods.goodsPrice}"></c:out></td>
      <td align=center id="goodsSell" class=txlrow><c:out
        value="${goods.goodsSell}"></c:out></td>
      <td align=center class=txlrow> <input type="button" value="編輯"></td>
     </tr>
    </c:forEach>

   </tbody>
  </table>

<!--分頁顯示-->
<div id="Pagination"></div>

js

var limit=<%=request.getAttribute("limit")%>;//每頁顯示多少 條數據
 var count=<%=request.getAttribute("count")%>//共多少條數據
 var index=<%=request.getAttribute("index")%>;//當前記錄數
$(function(){
 $("#Pagination").pagination(count, {
  items_per_page:limit, // 每頁顯示多少條記錄
  current_page: Math.ceil(index/limit), //當前頁
  num_display_entries:4, // 分頁顯示的條目數
  next_text:"下一頁",
  prev_text:"上一頁",
  num_edge_entries:2, // 連接分頁主體,顯示的條目數
  callback:handlePaginationClick
 });
});


function handlePaginationClick(new_page_index, pagination_container) {
  var path="<%=ppath%>/goodsManager/searchGoodsBylimit/" + new_page_index*limit;
  $("#goodsForm").attr("action",path );
  $("#goodsForm").submit();
  return false;

}

控制器

@RequestMapping(value = "/searchGoodsBylimit/{index}")
 public String searchGoodsBylimitPst(Model model,
   @ModelAttribute Goods goods, @PathVariable String index,
   HttpServletRequest request) {
  //索引
  if (index == null || index.equals("")) {
   index = "0";
  //從服務器獲取數據
  List<Goods> goodsS = goodsService.selectGoods(goods,
    Integer.parseInt(index), PageParam.limit);


  if (goodsS != null) {
   model.addAttribute("goodsS", goodsS);
  } else {
   model.addAttribute("resultMsg", "沒有該商品");
  }
  //數據總條數
  int count = goodsService.selectAllCount(goods);
  model.addAttribute("index", index);
  model.addAttribute("count", count);
  model.addAttribute("limit", PageParam.limit);

  System.out.println("第" + index + "數據開始顯示" + goodsS.size() + "條記錄");
  return "goodsManager/showGoods";
 }

效果圖

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持神馬文庫。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章