背景:原先是一次性查询加载到前段,表格插件自动分页,最近查询的数据量越来越大,长的时候需要等好几十秒,决定自己写一个后端分页,我写的和网上大神的略有不同,不是后端写一个类封装分页的参数,每次查询都是穿当前页码和查询行数,详见下文:
步骤:
首先实习分页,思路要理清,其实分页很简单,实习方式也有很多种,首先几个参数是必须的
后端需要的参数:
1:当前查询的页数
2:每页显示的行数
前端需要的参数:
总行数
一:前端修改:
前端我用的是原始的html标签构成几个基本的分页功能,再绑定具体的点击事件,改变事件
<style>
.dss_table_page{margin:0;padding:0;font-family:"Microsoft YaHei",Verdana;font-size:12px;height:30px;line-height:30px;100%;user-select: none;-ms-user-select: none;vertical-align:middle;border-top:solid 1px #ccc;margin-top:-1px;}
.dss_table_page div.dss_table_page_oper{320px;float:left;margin-left:10px;margin-top:3px;padding:0px;}
.dss_table_page div.dss_table_page_oper span{display:inline-block;margin:0 5px 0 0;padding:0px 6px;line-height:20px;height:20px;border:1px solid #e1e1e1;background:#fff;color:#333;text-decoration:none;cursor:pointer}
.dss_table_page div.dss_table_page_oper span.first_1{background-image:url('../../themes/lightblue/jqgrid/images/left1_a.png');background-repeat:no-repeat;background-position:center center}
.dss_table_page div.dss_table_page_oper span.prev_1{background-image:url('../../themes/lightblue/jqgrid/images/left2_a.png');background-repeat:no-repeat;background-position:center center}
.dss_table_page div.dss_table_page_oper span.next_1{background-image:url('../../themes/lightblue/jqgrid/images/right2_a.png');background-repeat:no-repeat;background-position:center center}
.dss_table_page div.dss_table_page_oper span.last_1{background-image:url('../../themes/lightblue/jqgrid/images/right1_a.png');background-repeat:no-repeat;background-position:center center}
.dss_table_page div.dss_table_page_oper span input{30px;height:17px;border:1px solid #e1e1e1;line-height:16px;margin-top:1px;}
.dss_table_page div.dss_table_page_oper span select{50px;height:22px;border:1px solid #e1e1e1;line-height:22px}
.dss_table_page div.dss_table_page_oper span.none{border:0px}
.dss_table_page span.sum{float:right;margin-right:10px}
</style>
<div id="report_0tp" role="w" class="dss_table_page">
<div class="dss_table_page_oper">
<span class="first_1"> </span>
<span class="prev_1"> </span>
<span class="none" id="countpage"><input id="curpage" type="text" value="1">
<a style="text-decoration:none;color:black" id="addcount"><a></span>
<span class="next_1"> </span>
<span class="last_1"> </span>
<span class="none">
<select id="displayrow">
<option value="20" selected="selected">20</option>
<option value="50">50</option>
<option value="100">100</option>
</select></span>
</div>