Js table paging implementation code. For more information, see.
The Code is as follows:
Original region Management
Script
Function Page (iAbsolute, sTableId, sTBodyId, page)
{
This. absolute = iAbsolute; // maximum number of records per page
This. tableId = sTableId;
This. tBodyId = sTBodyId;
This. rowCount = 0; // number of records
This. pageCount = 0; // Number of pages
This. pageIndex = 0; // page index
This. _ oTable _ = null; // Table reference
This. _ oTBody _ = null; // the content to be paged
This. _ dataRows _ = 0; // record row Reference
This. _ oldTBody _ = null;
This. _ init _ (); // initialization;
};
/**//*
Initialization
*/
Page. prototype. _ init _ = function (){
This. _ oTable _ = document. getElementById (this. tableId); // obtain table reference
This. _ oTBody _ = this. _ oTable _. tBodies [this. tBodyId]; // obtain the tBody reference
This. _ dataRows _ = this. _ oTBody _. rows;
This. rowCount = this. _ dataRows _. length;
Try {
This. absolute = (this. absolute <= 0) | (this. absolute> this. rowCount )? This. rowCount: this. absolute;
This. pageCount = parseInt (this. rowCount % this. absolute = 0
? This. rowCount/this. absolute: this. rowCount/this. absolute + 1 );
} Catch (exception ){}
This. _ updateTableRows __();
};
Page. prototype. GetBar = function (obj)
{
Var bar = document. getElementById (obj. id );
Bar. innerHTML = "per page" + this. absolute + "entries/total" + this. rowCount + "entries"; // 2nd pages/6 Pages in total homepage Previous Page 1 2 3 4 5 6 next page last page
}
/**//*
Next Page
*/
Page. prototype. nextPage = function (){
If (this. pageIndex + 1 <this. pageCount ){
This. pageIndex + = 1;
This. _ updateTableRows __();
}
};
/**//*
Previous Page
*/
Page. prototype. prePage = function (){
If (this. pageIndex> = 1 ){
This. pageIndex-= 1;
This. _ updateTableRows __();
}
};
/**//*
Homepage
*/
Page. prototype. firstPage = function (){
If (this. pageIndex! = 0 ){
This. pageIndex = 0;
This. _ updateTableRows __();
}
};
/**//*
Last page
*/
Page. prototype. lastPage = function (){
If (this. pageIndex + 1! = This. pageCount ){
This. pageIndex = this. pageCount-1;
This. _ updateTableRows __();
}
};
/**//*
Page Locating Method
*/
Page. prototype. aimPage = function (){
Var abc = document. getElementById ("pageno ");
Var iPageIndex = abc. value;
Var iPageIndex = iPageIndex * 1;
If (iPageIndex> this. pageCount-1 ){
This. pageIndex = this. pageCount-1;
} Else if (iPageIndex <0 ){
This. pageIndex = 0;
} Else {
This. pageIndex = iPageIndex-1;
}
This. _ updateTableRows __();
};
/**//*
When the page is executed, update the display table content
*/
Page. prototype. _ updateTableRows _ = function (){
Var iCurrentRowCount = this. absolute * this. pageIndex;
Var iMoreRow = this. absolute + iCurrentRowCount> this. rowCount? This. absolute + iCurrentRowCount-this. rowCount: 0;
Var tempRows = this. _ cloneRows __();
Var removedTBody = this. _ oTable _. removeChild (this. _ oTBody __);
Var newTBody = document. createElement ("TBODY ");
NewTBody. setAttribute ("id", this. tBodyId );
For (var I = iCurrentRowCount; I <this. absolute + iCurrentRowCount-iMoreRow; I ++ ){
NewTBody. appendChild (tempRows [I]);
}
This. _ oTable _. appendChild (newTBody );
This. _ dataRows _ = tempRows;
This. _ oTBody _ = newTBody;
// Footer display score
Var pFood = document. getElementById ("pFood"); // pagination Toolbar
PFood. innerHTML = "";
Var rightBar = document. createElement ("pFood ");
RightBar. setAttribute ("display ","");
RightBar. setAttribute ("float", "left ");
RightBar. innerHTML = "th" + (this. pageIndex + 1) + "Page/total" + this. pageCount + "page ";
Var isOK = "Y ";
Var cssColor = "";
PFood. appendChild (rightBar );
/// Display the footer by PAGE
};
/**//*
Clone a collection of original operation rows
*/
Page. prototype. _ cloneRows _ = function (){
Var tempRows = [];
For (var I = 0; I TempRows [I] = this. _ dataRows _ [I]. cloneNode (1 );
}
Return tempRows;
};
Script