1. 程式人生 > >一、jq前端分頁外掛pagination使用

一、jq前端分頁外掛pagination使用

前端採用pagination分頁外掛,後端用ssm框架。

下載jquery.pagination.js.

        normalize.css

        pagination.css

        其中 pagination.css修改你想要的樣式

       我用的是這個網頁的分頁外掛http://www.jq22.com/jquery-info5697

        

       下面講程式碼(上面網頁中api已經講得非常清楚了我只講與後端搭建)

       前端:

               當然首先得先引入js和css

                <link rel="stylesheet" type="text/css" href="css/normalize.css" media="screen">
<link rel="stylesheet" type="text/css" href="css/pagination.css" media="screen">

                <script src="js/jquery.min.js"></script>
<script src="js/jquery.pagination.js"></script>

               再則寫div

               <div class="wrapper">
<div class="eg">
<div class="M-box"></div>
<div class="tips">當前是第<span class="now">1</span>頁,總共<span class="total"></span>頁,總共<span class="count"></span>條資料</div>
</div>
</div>

              再配置pagination

              <script>
$(function() {
var totalPage = 1;//總共多少頁
var totalRecords = 1;//總共多少條
var pageSize=4;//每頁顯示多少頁
loadList(1);//初始化顯示第一頁
function loadList(pno)
{
$.ajax({
type:"post",
   url:"/login/s/usercontroller/searchBusiEventInfo",//ajax獲取地址
dataType: "json",
data: { 'pageNum': pno,'pageSize': pageSize},//傳給後端的引數
success:function(result) {//成功後返回json資料
console.log(result);
console.log(pno);
if (result.success) {
var count = result.total;
                   var data = result.rows;
                   totalRecords = count;//總共多少條
                   totalPage = Math.ceil(count / pageSize);//總共多少頁
                   var datalist="";
$.each(data, function(i, item) {//迴圈取出資料
datalist+='<tr>'+
     '<td>'+item.uid+'</td>'+
                 '<td>'+item.username+'</td>'+
                 '<td>'+item.userpassword+'</td>'+
             '</tr>';
       });
$("#datalist1").html(datalist);
$('.total').text(totalPage); 
$('.count').text(count); 
$('.M-box').pagination({
pageCount: totalPage,
current:pno,//當前第幾頁
jump: true,
coping: true,
homePage: '首頁',
endPage: '末頁',
prevContent: '上頁',
nextContent: '下頁',
callback:PageClick//點選事件後回撥
});
}
},
           error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('網路連線異常,請重試!')
           }
});
}
                //回撥函式  
                PageClick = function(index){
                    $('.now').text(index.getCurrent()); 
 loadList(index.getCurrent());//點選分頁載入列表資料  */
               }
});
</script>

           原始碼:

<!DOCTYPE html>
<html lang="cn-ZH">

	<head>
		<meta charset="UTF-8">
		<title>Mss。-pagination</title>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" type="text/css" href="css/normalize.css" media="screen">
		<link rel="stylesheet" type="text/css" href="css/pagination.css" media="screen">
	</head>

	<body>
	  <table width="80%" align="center">
    <tr>
      <td>id號</td>
      <td>名字</td>
      <td>密碼</td>
    </tr>
    <tbody id="datalist1">
    </tbody>
  </table>
		<div class="wrapper">
			<div class="eg">
				<div class="M-box"></div>
				<div class="tips">當前是第<span class="now">1</span>頁,總共<span class="total"></span>頁,總共<span class="count"></span>條資料</div>
			</div>
		</div>

		<script src="js/jquery.min.js"></script>
		<script src="js/jquery.pagination.js"></script>
		<script>
			$(function() {
				var totalPage = 1;//總共多少頁
				var totalRecords = 1;//總共多少條
				var pageSize=4;//每頁顯示多少頁
				loadList(1);
				function loadList(pno)
				{
				$.ajax({
					type:"post",
				    url:"/login/s/usercontroller/searchBusiEventInfo",
					dataType: "json",
					data: { 'pageNum': pno,'pageSize': pageSize},
					success:function(result) {
						console.log(result);
						console.log(pno);
						if (result.success) {
							var count = result.total;
		                    var data = result.rows;
		                    totalRecords = count;
		                    totalPage = Math.ceil(count / pageSize);
		                    var datalist="";
							$.each(data, function(i, item) {
								datalist+='<tr>'+
									      '<td>'+item.uid+'</td>'+
					            		      '<td>'+item.username+'</td>'+
					            		      '<td>'+item.userpassword+'</td>'+
					            		  '</tr>';
					        });
							$("#datalist1").html(datalist);
							$('.total').text(totalPage); 
							$('.count').text(count); 
							$('.M-box').pagination({
								pageCount: totalPage,
								current:pno,//當前第幾頁
								jump: true,
								coping: true,
								homePage: '首頁',
								endPage: '末頁',
								prevContent: '上頁',
								nextContent: '下頁',
								callback:PageClick
							});
						}			
					},
		            error: function (XMLHttpRequest, textStatus, errorThrown) {
							alert('網路連線異常,請重試!')
		            }
				});
				}
                //回撥函式  
                PageClick = function(index){
                    $('.now').text(index.getCurrent()); 
 					loadList(index.getCurrent());//點選分頁載入列表資料  */
               }
			});
		</script>
	</body>

</html>
       後端:

        寫個分頁攔截器用mybatis 分頁外掛進行分頁

public class PageInterceptor extends HandlerInterceptorAdapter {

	private static final Logger logger = LoggerFactory.getLogger(PageInterceptor.class);
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		String pageNum = request.getParameter("pageNum");// 開始頁數
		String pageSize = request.getParameter("pageSize");// 每頁行數
		if (StringUtils.isNotBlank(pageNum) && StringUtils.isNotBlank(pageSize)) {
			try {
				PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
			} catch (Exception e) {
				logger.error(String.format("page分頁攔截異常,原因:%s", e.getMessage()));
			}
		}
		return true;
	}
	
}
       寫個介面接收資料
	public PageResult4EUjson(){		
		List<Users> list =usersService.getAllUsers();
		logger.info("後端_使用者分頁顯示"); 
		return ResResult.ok(list).toPageResult();
	}


        效果圖


相關推薦

jq前端外掛pagination使用

前端採用pagination分頁外掛,後端用ssm框架。 下載jquery.pagination.js.         normalize.css         pagination.css         其中 pagination.css修改你想要的樣式      

jq前端外掛jqgrid

1.寫div <div class="ibox-content"><div class="jqGrid_wrapper"><!-- jqGrid資料列表    開始--><table id="table_list_1"><

前端外掛pagination

ajax請求每頁資料,根據返回資料生成頁碼<link href="~/Scripts/pagination/pagination.css" rel="stylesheet" /> <script src="~/Scripts/pagination/pagin

款不錯的jQuery外掛--pagination

一、前言: 分頁功能在專案中時常用到,一款可以快速實現分頁功能的外掛非常有必要,pagination--這款外掛功能非常完美,幾乎我所有專案中使用到分頁的地方都會第一時間考慮到這個外掛,但是其實有能力

angularJS前端外掛

  首先在專案中引入 分頁外掛的 js 和 css:   在html頁面引入 相關js 和 css;   在控制器中引入分頁外掛中定義的 module【可以開啟pagination.js檢視,可以看到 其實,在外掛裡面,它定義了一個單獨的 module,所

前端外掛 laypage.js laypage.css

分頁外掛使用步驟: 匯入css/js外掛資源放入到js目錄下--------------------------------------- <link rel="stylesheet" href="js/skin/laypage.css">

複雜查詢顯示前端實現-使前端外掛myPagination

由於國內關於myPagination外掛的文件並不多,由於參照官方給的文件一直出現問題, 所以自己摸索出了一種新的食用方法。 定義全域性變數和預設搜尋條件 var searchJson

前端外掛常見問題總結

關於前端分頁功能實現常見問題分析 2018-10-30 18:23:59 董坤 0 初次使用前端分頁外掛,會出現Cannot read property ‘mData’ of undefined或者 Cannot read property ‘sWidth’

Spring Boot系列教程十: Mybatis使用外掛PageHelper

一.前言 上篇部落格中介紹了spring boot整合mybatis的方法,基於上篇文章這裡主要介紹如何使用分頁外掛PageHelper。在MyBatis中提供了攔截器介面,我們可以使用PageHelp最為一個外掛裝入到SqlSessionFactory,實現攔截器功能。

ajax非同步外掛pagination詳解

<script type="text/javascript"> if(window.name){ // 重新整理獲取頁碼 } $('.M-page').pagination

jq插件(pagination.min.js)

NPU trac .html 固定 www. default 開始 cit pty 首先引入jq,再引pagination.min.js和pagination.css html: <div id="pagingmix" class="page m-style M-

使用pagination外掛實現ajax

1.html頁面引入jq和js外掛 <script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <s

Jquery 外掛, 帶你步接入後臺資料

目錄   一、效果圖 二、分頁 js 原始碼講解 三、分頁樣式 css 原始碼 三、實現前後臺對接 一、效果圖 二、分頁 js 原始碼講解 新建一個 js 檔案,基本直接複製貼上就行,記得引入到需要的頁面中。 需要注意的是: 前面的建構函式

VUE-002-前端(el-pagination)展示資料

在web開發過程中,通常使用表格展示資料,在資料較多時採用分頁的方式展示給使用者。 分頁方式有前端假分頁和後端分頁兩種實現方式,此文僅記錄前端假分頁實現方式。   第一步:新增分頁元件(el-pagination)在表格下方,新增的程式碼如下所示: <template>

前端小結2--jQuery外掛JPaginate的詳細使用

前端小結2–jQuery分頁外掛JPaginate的詳細使用 java web開發中,後臺分頁後,前端需要分頁按鈕來顯示。 這裡介紹幾個好用的jQuery分頁外掛:http://www.jq22.com/jquery-info34 對前端搞的少,之前都是jsp,ajax實在是

angular的tm-pagination外掛一個頁面使用多個的問題

很多分頁外掛在一個頁面中使用多個的時候都會出現一些問題(據說的,我還沒有什麼經驗),當然我在使用tm-pagination的時候也沒有跳過這個坑,先上個pagination最基礎的使用。其中有幾點需要注意的地方 1.外掛有兩個關鍵引數currentPage、itemsPerPage,當前頁碼和每

外掛pagehelper初使用,前端傳遞當前頁碼與每條數後臺接受實現

最新的專案用到了pagehelper分頁外掛,在此做下筆記方便以後檢視!同時也希望能對別人產生幫助。 1.因為專案是maven進行管理的,所以:第一步就是在pom.xml檔案中引入pagehelper分頁外掛。 <dependency> <groupId>com

springboot2.0.5整合mybatis(PageHelper外掛generator外掛使用)

用IDEA搭建springboot2.0.5專案 選擇Spring initializr就可以輕鬆搭建一個springboot專案,第一次搭建很費時 在Group寫上公司域名,Artifact寫上專案名,打包用Jar 選Web勾選 SQL項,勾選MySQL

Spring Boot2 + Mybatis 整合(Mybatis自動生成外掛外掛)

內容: Spring Boot2 + Mybatis 整合 Mybatis Generator自動生成程式碼 Mybatis PageHelper分頁外掛

Mybatis-Plus來學習一下!程式碼生成外掛

在這裡小小推薦下我的個人部落格 簡書:雷園的簡書 今天我們來說一下Mybatis-Plus! 個人認為呢,Mybatis-Plus是Mybatis的增強版,他只是在Mybatis的基礎上增加了功能,且並未對原有功能進行任何的改動。可謂是非常良心的一款開源