What I did for paging at the moment is to create a Pager control. To update, I need a paging URL, html element identifier, page number, page size and total.
The paging URL is in the form of a controller / action in which the action returns an html string (display data page)
The pager adds a list of javascript links for pages. These links invoke the jQuery-based ajax function, which hits the paging URL. Each click on the page replaces the current content of the html element with the results of the ajax call. Something like that:
public string Render() { var buffer = new StringBuilder( 1000 ); buffer.AppendLine( @"<ul class=""datatable_pager"">" ) .AppendLine( "\t<li>Additional Pages:</li>" ); int numberOfPages = TotalItemCount % PageSize == 0 ? TotalItemCount / PageSize : TotalItemCount / PageSize + 1; for( int i = 0; i < numberOfPages; i++ ) { AppendPageLink( buffer, i ); } buffer.AppendLine( "\t</ul>" ); AppendPagingJS( buffer ); return buffer.ToString( ); } private void AppendPageLink( StringBuilder buffer, int i ) { buffer.Append( "\t\t<li><a href=\"" ) .Append( PagingLink.Replace( "$PAGE$", i.ToString( ) ) ) .Append( "\">" ) .Append( i.ToString( ) ) .Append( "</a>" ) .AppendLine( "\t\t</li>" ); } private void AppendPagingJS( StringBuilder buffer ) { buffer.AppendLine( @" <script type=""text/javascript""> function page( page, size, updateElement ) { $.post( '" + PagingUrl + @"', { pageNumber: page, pageSize: size, }, function(response) { $(""#"" + updateElement).html(response); }, ""html"" ); } </script>" ); }
Javascript messages to the paging url, so to do this you need to do the following:
int.TryParse (Request.Params ["pageNumber"], out page) int.TryParse (Request.Params ["pageSize"], size out))
and use the results with your data access components to grab the data page, make it as html and return it.
Hope this helps, I can expand it if necessary.
µBio
source share