Click here to Skip to main content
Click here to Skip to main content

Client Side Gridview Pagination using JQuery

By , 10 Jun 2009
 
2.JPG

Introduction 

Here, I would like to show how to use Client Side Gridview Pagination using Jquery Table Pagination Plugin by using Ryan Zielke.  

Using the Code

First create a folder called "images". Then paste all the image files into that folder.

1.JPG

Next, add the reference of Jquery and Plugin JavaScript file in the ASPX Page.   

<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="jquery.tablePagination.0.1.js" type="text/javascript"></script>

Then add the CSS below. Here Width value of #testTable must be the same as the Width of your Gridview control.

#testTable { 
            width : 300px;
            margin-left: auto; 
            margin-right: auto; 
          }
          
           #tablePagination { 
            background-color:  Transparent; 
            font-size: 0.8em; 
            padding: 0px 5px; 
            height: 20px
          }
          
          #tablePagination_paginater { 
            margin-left: auto; 
            margin-right: auto;
          }
          
          #tablePagination img { 
            padding: 0px 2px; 
          }
          
          #tablePagination_perPage { 
            float: left; 
          }
          
          #tablePagination_paginater { 
            float: right; 
          }

Finally, add this script in your ASPX Page:

<script type ="text/javascript" >
	$(document).ready(
 	function() {
 	$('table').tablePagination({});
 	});
 	</script> 

Now, add Gridview1_PreRender method in code behind, unless during paging you cannot see the Header of Gridview. Generally, Gridview does not use tbody, thead, or tfoot tags for the table that is generated when rendered in the browser. So, for Tbody and Thead, we need to add this function:

 protected void GridView1_PreRender(object sender, EventArgs e)
 {
     GridView1.UseAccessibleHeader = false;
     GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
 }

Configuration

You can change different parameters of jquery.tablePagination.0.1.js. Below are some of the settings from the authors Site:

  • firstArrow - Image - Pass in an image to replace default image.
    Default: (new Image()).src="./images/first.gif"
  • prevArrow - Image - Pass in an image to replace default image.
    Default: (new Image()).src="./images/prev.gif"
  • lastArrow - Image - Pass in an image to replace default image.
    Default: (new Image()).src="./images/last.gif"
  • nextArrow - Image - Pass in an image to replace default image.
    Default: (new Image()).src="./images/next.gif"
  • rowsPerPage - Number - used to determine the starting rows per page.
    Default: 5
  • currPage - Number - This is to determine what the starting current page is. Default: 1
  • optionsForRows - Array - This is to set the values on the rows per page.
    Default: [5,10,25,50,100]
  • ignoreRows - Array - This is to specify which 'tr' rows to ignore. It is recommended that you have those rows be invisible as they will mess with page counts.
    Default: [].

For the Future Release of Table Pagination Plugin

History

  • 10th June, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

sagnik mukherjee
Web Developer
India India
Member
I am from India, currently i am working in Microsoft Platform for building web and mobile applications.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionMy vote is 5memberaaronjave16 Apr '13 - 6:24 
Thank you sir!
Questionpagination works if only the window is refreshedmemberkasirajan -7 Apr '13 - 22:52 
Hai, I got solution for my long search for pagination in client side with your jquery pagination plugin.First of all i thank you for that.
 
My doubt is, at every first time, your plugin is showing paginated records correctly like , it will take records alone from database without table or grid heading and if i once again search datas from database , its taking grid heading also as first row and in next page, its now showing table heading. Please help me in this. Other than this, I like your pagination plugin very much.
 
Please get me out of this problem. Thanks in advance Smile | :) Waiting for your answer. . .
QuestionContentPlace HoldermemberReima Cram24 Jan '13 - 20:04 
Hi There, this may be so simple but i'm having a hard time.
I followed the steps and thought it was working fine but then when the number of rows exceeded the selected number of rows per page, when I click the next button, the whole page turned white. I was thinking this was because I have a master page. and the effect of paging was to render the whole page.
 
PLease kindly advise.
 
PS: Please bear patience with a beginner like me Wink | ;)
QuestionThanksmemberavinashinde202028 Nov '12 - 2:04 
Good Solution thank you
QuestionThis doesnt work if we do a server side Data Bindmembermsdnexpert7 Oct '11 - 4:19 
This sample doesnt seem to work if we do a server side databind? Any reason for that
AnswerRe: This doesnt work if we do a server side Data Bindmemberpkaminiv17 May '12 - 23:20 
first time all data are coming and paging will be done based on it..i want the records at once defined by pagesize. so if click on 2 page then request goes server side through jquery and display records...is it possible in this?
friends

QuestionPaging in numbermembermegha.khamar@gmail.com17 Aug '11 - 23:59 
I want to display paging in number to top and bottom from gridview
GeneralPrerender method for DataGridmemberu4bharat10 Jun '11 - 1:51 
Hi
I m applying this control on DataGrid.My problem is that when i m move the next page, the header row is lost. I checked in Prerender method but there is no HeaderRow member in DataGrid control.
 
Please help me.
Thanks in advance.
GeneralAdd Pager to a Repeatermembernipunasilva23 May '11 - 20:52 
I'm using a repeater in my website. How can I add this pager to a repeater???
GeneralMy vote of 5membernipunasilva23 May '11 - 20:50 
Nice Article. How can I did this pager to a Data Repeater????

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 10 Jun 2009
Article Copyright 2009 by sagnik mukherjee
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid