JQuery paging plug-in and jQuery paging plug-in
The source code is as follows:
[Javascript]View plaincopyprint?
- $. Fn. pager = function (pagerInfo ){
- Var recordCount = this. size ();
- If (recordCount <= pagerInfo. pagesize) return;
- Var currentPageIndex = 1, // The current surface. The default value is 1.
- PageCount = Math. ceil (recordCount/pagerInfo. pagesize); // total number of pages
- // Construct the html of the page
- $ ('<Div> total' + this. size () + 'records, total '+ pageCount +' page, current <span> 1 </span> page </div> ')
- . InsertAfter (pagerInfo. container)
- . Append ($ ('<a class = "prev-page"> previous page </a>'). click (function (){
- If (currentPageIndex = 1) return;
- CurrentPageIndex --;
- ShowRecords (currentPageIndex );
- $ (This). prev ('span '). text (currentPageIndex );
- }))
- . Append ($ ('<a class = "prev-page" href> next page </a>'). click (function (){
- If (currentPageIndex = pageCount) return;
- CurrentPageIndex ++;
- ShowRecords (currentPageIndex );
- $ (This). prevAll ('span '). text (currentPageIndex );
- }))
- .Css(pagerInfo.css)
- .Find('span'apps.css ({padding: 0 });
- Var jRecords = this; // reserved Scope
- // PageIndex starts with 1
- Var showRecords = function (pageIndex ){
- JRecords. hide (); // hide all records first
- Var startIndex = (pageIndex-1) * pagerInfo. pagesize, // start record of the current page
- EndIndex = (pageIndex * pagerInfo. pagesize)-1; // end record of the current page
- JRecords. filter (': eq (' + startIndex + '),: gt (' + startIndex + ')'). show (); // display all records greater than the start record (inclusive)
- JRecords. filter (': gt (' + endIndex + '). hide (); // hide all records greater than the end record to achieve paging Effect
- };
- ShowRecords (currentPageIndex );
- };
Example:
[Javascript]View plaincopyprint?
- $ ('# Feedback ul li') // Data Source
- . Pager ({
- Pagesize: 10, // page size
- Container: $ ('# feedback'), // container that contains html pages
- Css: {'margin-left': '40px '} // pagination html Style
- });
Use jquery plug-in to implement Paging
Jquery has a plug-in called dataTables. You can find it.
Jquery. dataTables. min. js
Who has JQuery's paging plug-in and demo? The next page and the total number of pages on the previous page, the jump box, and the digital navigation?
It is convenient to use the pagination plug-in of jquery:
<Div id = "Pagination" class = "pagination"> <! -- The paging navigation is displayed here --> </div>
<Script>
$ (Function (){
Var num_entries = 1000; // This is the total number of entries to be displayed
$ ("# Pagination"). pagination (num_entries ,{
Num_edge_entries: 1, // Number of edge pages
Num_display_entries: 10, // number of subject pages
Callback: pageselectCallback, // callback function. In this function, write the display list code.
Items_per_page: 50, // number of items displayed on each page
Prev_text: "Previous Page ",
Next_text: "Next page"
});
});
// Callback function
Function pageselectCallback (page_index, jq ){
// Load the page display content through ajax
$. Post ("ServerCode", {pageno: page_index}, function (result ){
// The result is traversed and displayed.
});
});
</Script>
// Server ServerCode
Receive the pageno parameter and return the information to be displayed on this page.