本文執行個體講解了基于jquery實作表格無重新整理分頁功能,分享給大家供大家參考,具體内容如下
效果圖:
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5CO3kzM5cDMiVjNyEmZxMmY3cDO0YmZ4gjZiVGZ5cTM48CX0JXZ252bj91Ztl2Lc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
具體代碼:
面向對象的無重新整理表格分頁
var data = [];
for(var i=0;i<103;i++){
data[i] = {id:i+1,name:"jason"+(i+1),gender:"男",age:i+1,address:"成都"};
}
var cs = new table({
"tableId":"cs_table", //必須 表格id
"headers":["序号","姓名","性别","年齡","位址"], //必須 thead表頭
"data":data, //必須 tbody 資料展示
"displayNum": 10, //必須 預設 10 每頁顯示行數
"groupDataNum":5, //可選 預設 10 組數
"display_tfoot":true, // true/false 是否顯示tfoot --- 預設false
"bindContentTr":function(){ //可選 給tbody 每行綁定事件回調
this.tableObj.find("tbody").on("click",'tr',function(e){
return false;
var tr_index = $(this).data("tr_index"); // tr行号 從0開始
var data_index = $(this).data("data_index"); //資料行号 從0開始
})
},
sort:true, // 點選表頭是否排序 true/false --- 預設false
sortContent:[
{
index:0,//表頭序号
compareCallBack:function(a,b){ //排序比較的回調函數
var a=parseInt(a.id,10);
var b=parseInt(b.id,10);
if(a < b)
return -1;
else if(a == b)
return 0;
else
return 1;
}
},
{
index:3,//表頭序号
compareCallBack:function(a,b){ //排序比較的回調函數
var a=parseInt(a.age,10);
var b=parseInt(b.age,10);
if(a < b)
return -1;
else if(a == b)
return 0;
else
return 1;
}
}
],
specialRows:[
{
row:4,
cssText:{
"color":"#FFCF17"
}
}
],
search:true // 預設為false 沒有搜尋
});
html,body{margin: 0;padding:0}
a:focus {outline: none;}
h3.head_title {border-bottom: 1px solid #d5ddeb;color: #1c7493;display: block;font-size: 14px;height: 30px;line-height: 30px;margin-bottom: 10px;}
table, th, td {font: 12px Arial,Helvetica,sans-serif,'宋體';margin: 0;padding: 0}
table{border-spacing: 0;border-collapse: collapse;empty-cells: show}
.data-table {width: 100%;border-style: none;background-color: #fff;text-align: left;}
.data-table th, .data-table td { padding: 5px;line-height: 30px}
.data-table thead th {background-color: #eee;margin: 0;text-align: left;border-top: 1px solid #cfcfcf;border-bottom: 1px solid #cfcfcf;font-weight: 500}
.data-table tbody td {background-color: #fff;border-bottom: 1px dotted #ddd;table-layout:fixed;word-break:break-all;border-collapse:collapse;font-weight: 400}
.data-table tbody tr.evenrow td {background-color: #f4f4f4;}
.data-table tfoot td {background-color: #fafafa;text-align: right;border-bottom: 1px solid #cfcfcf;}
.data-table td.paging a {border: 1px solid #eee; color: #444; margin: 4px; padding: 2px 7px; text-decoration: none; text-align:center;}
.data-table td.paging a.current {background: #eee; border: 1px solid #CFCFCF; color: #444; font-weight: bold;}
.data-table td.paging input{border:1px solid #4D90BB;font-family:Arial,sans-serif,Tahoma; font-size:12px; padding:0 5px;outline: none}
.data-table td.paging .search-txt{height:30px;line-height:30px;width: 100px }
.data-table td.paging .search-btn{height: 32px;border-left:none;cursor: pointer;_filter:chroma(color=#000000);_border:none;}
.data-table thead th.bg{background:#eee url("../images/bg.gif") right center no-repeat;cursor: pointer}
.data-table thead th.asc{background: url("../images/asc.gif") right center no-repeat;cursor: pointer}
.data-table thead th.desc{background: url("../images/desc.gif") right center no-repeat;cursor: pointer}
以上就是基于jquery實作表格無重新整理分頁功能的詳細代碼,希望對大家的學習有所幫助。