CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [terrykhatri531] Need help to improve pagination: Edit Log



Zhris
Enthusiast

Aug 2, 2014, 8:37 AM


Views: 35392
Re: [terrykhatri531] Need help to improve pagination

I think I now understand your concept, but its totally unnecessary. The image you attached shows that the script has been passed the parameter page=15. You need to set the currentPage option of the pagination plugin to this value. Its as simple as that, just as my example above entails, play with the demo I linked to, look at url query string and compare with the source code etc.

If you require any further help from us Perl guys, please post all relevant code.

Finally, for reference, here is a more complete version of my example above. It uses Data::Page to do all the core calculations then passes whats necessary to the plugin. It is a lot more forgiving under race conditions and we can fetch the resultset without any additional work. This is the beginnings of a pure Data::Page solution.

http://test.massweb.co.uk/paginationb.pl

Code
#!/usr/bin/perl  
use strict;
use warnings;
use CGI::Carp qw/fatalsToBrowser/;
use CGI;
use Data::Page;
use HTML::Template;

my $items = 100;

my $cgi = CGI->new;

my $items_on_page = $cgi->param('items_on_page');
my $current_page = $cgi->param('current_page');

$items_on_page = 10 unless ($items_on_page =~ m/^[1-9]\d*$/);

my $page = Data::Page->new;

$page->total_entries($items);
$page->entries_per_page($items_on_page);
$page->current_page($current_page);

my $offset = $page->first;
my $limit = $page->entries_on_this_page;
my $info = 'page: ' . $page->current_page . ', first: ' . $page->first . ', last: ' . $page->last . ', offset: ' . $offset . ', limit: ' . $limit;

my $template = HTML::Template->new(filehandle => \*DATA);

$template->param(pages => $page->last_page);
$template->param(current_page => $page->current_page);
$template->param(items_on_page => $page->entries_per_page);
$template->param(info => $info);

print $cgi->header, $template->output;

__DATA__
<html>
<head>
<script type="text/javascript" language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" language="javascript" src="http://flaviusmatis.github.io/simplePagination.js/jquery.simplePagination.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$(".mypagination").pagination({
pages: <TMPL_VAR NAME=pages>,
currentPage: <TMPL_VAR NAME=current_page>,
hrefTextPrefix: 'paginationb.pl?items_on_page=<TMPL_VAR NAME=items_on_page>&current_page=',
});
});
</script>

<link type="text/css" rel="stylesheet" href="http://flaviusmatis.github.io/simplePagination.js/simplePagination.css"/>
</head>
<body>
<p><TMPL_VAR NAME=info>.</p>
<div class="mypagination">
<p>error loading pagination.</p>
</div>
</body>
</html>


Regards,

Chris


(This post was edited by Zhris on Aug 2, 2014, 8:40 AM)


Edit Log:
Post edited by Zhris (Enthusiast) on Aug 2, 2014, 8:37 AM
Post edited by Zhris (Enthusiast) on Aug 2, 2014, 8:40 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives