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:
[SOLVED] Need help to improve pagination

 

First page Previous page 1 2 Next page Last page  View All


terrykhatri531
User

Jul 21, 2014, 7:03 AM

Post #1 of 35 (3138 views)
[SOLVED] Need help to improve pagination Can't Post

Hi,

I have created pagination using the following code it works but does not look graceful as it displays links for all 103 pages what I need help for is to make it compact like : [First][Prev][1][2][3][4][5][6]...[103][Next][last] the way its shown in the attached picture, I have looked at perl pagination modules @ cpan but there aren't enough examples for a guy of my level to use them.


Code
  
# Count how many rows are there in a table, so that we can use it for $pagenum.
my $sql = qq!SELECT COUNT(*) from "Orders" !;
my $sth = $dbh->prepare ("$sql");
$sth->execute() || quit();
my @row = $sth->fetchrow_array;
$sth->finish;

# Setting offset, limit and page number
my $offset = 0;
my $limit = 8;
my $pagenum = ceil($row[0]/$limit);

# Assigning value to $offset as 0 or whatever will be the $pagenum i.e. 1 or 2 ....
$offset=param('page')? $limit*param('page') :0;

# Get the data
$sql = qq!SELECT
a."OrderID", b."CompanyName" AS "CustomerName",
c."FirstName"::text || ' ' ||c."LastName"::text AS "EmployeeName",
a."OrderDate"::DATE, a."RequiredDate"::DATE, a."ShippedDate"::DATE,
d."CompanyName" AS "ShipVia", a."Freight", a."ShipName",
a."ShipAddress", a."ShipCity", a."ShipRegion",
a."ShipPostalCode", a."ShipCountry"
FROM
"Orders" a, "Customers" b, "Employees" c, "Shippers" d
WHERE
a."CustomerID" = b."CustomerID" AND
a."EmployeeID" = c."EmployeeID" AND
a."ShipVia" = d."ShipperID"
ORDER BY 1
LIMIT $limit OFFSET $offset !;

$sth=$dbh->prepare("$sql");
$sth->execute() || quit();

.... then html stuff skiped....

# Showing page number with link
my $first_page = $pagenum - $pagenum ;
my $last_page = $pagenum - 1;
$pagenum = $pagenum - 1;

print q(<ul class="tsc_pagination tsc_paginationA tsc_paginationA09">);
print qq(<li><a href='vieword.pl?page=$first_page'>First</a></li>);
for my $i (0 .. $pagenum)
{
print qq(<li><a href='vieword.pl?page=$i'>$i</a></li>);
}
print qq(<li><a href='vieword.pl?page=$last_page'>Last</a></li>);
print q(</ul>);


I have also attached a jquery plugin which I believe can be integrated with my code but I don't have a clue how, it shows how a light compact pagination may look with the js script, which you experienced gurus can understand.

Your help as usual will be much appreciated.

Many thanks !

Terry


(This post was edited by terrykhatri531 on Aug 8, 2014, 8:59 AM)
Attachments: How I want.png (2.28 KB)
  My Pagination.png (21.8 KB)
  js-pagination.zip (5.54 KB)


Laurent_R
Veteran / Moderator

Jul 21, 2014, 10:44 AM

Post #2 of 35 (3122 views)
Re: [terrykhatri531] Need help to improve pagination [In reply to] Can't Post

Cross-posted on the Perl Monks forum: http://www.perlmonks.org/?node_id=1094521

There is nothing wrong with cross posting questions, but it is considered polite to inform people about it to avoid duplication of work in various places of the Internet.


terrykhatri531
User

Jul 22, 2014, 11:12 AM

Post #3 of 35 (3062 views)
Re: [terrykhatri531] Need help to improve pagination [In reply to] Can't Post

Hi Chris,

You seem to be very busy !!! meanwhile I have been playing with the attached jquery/javascript, there are 2 major issues with it.



1) In the init function of jquery.simplePagination.js there is a variable hrefTextPrefix which is set to '#page-', which is no good for perl (right ?) so it does not work with my script and when I change it to '?page=' it does not go along with the javascript as it fails to read the URL to determine which page we are at. Since you know it better do you think there is something that can be done which is good for both perl and javascript.

Here are a few lines of the js pagination script :


Code
 
(function($){

var methods = {
init: function(options) {
var o = $.extend({
items: 1,
itemsOnPage: 1,
pages: 0,
displayedPages: 5,
edges: 2,
currentPage: 1,
hrefTextPrefix: '#page-',
hrefTextSuffix: '',
prevText: 'Prev',
nextText: 'Next',
ellipseText: '&hellip;',
cssStyle: 'light-theme',
labelMap: [],
selectOnClick: true,
onPageClick: function(pageNumber, event) {

.......




2) The 2nd problem is that the total number of pages is hardcoded in another js script called script.js which is :


Code
 
$('#light-pagination').pagination({
pages: 103,
cssStyle: 'light-theme'
});

$('#dark-pagination').pagination({
pages: 103,
cssStyle: 'dark-theme',
displayedPages: 3,
edges: 3
});

$('#compact-pagination').pagination({
pages: 103,
cssStyle: 'compact-theme',
displayedPages: 7
});


I do am looking forward to your assistance in getting my pagination right, this is one major snag in my application.

Many many thanks !!!

Terry


hwnd
User

Jul 22, 2014, 1:09 PM

Post #4 of 35 (3046 views)
Re: [terrykhatri531] Need help to improve pagination [In reply to] Can't Post

http://perlguru.com/gforum.cgi?post=73921;guest=15814725#73921


Zhris
Enthusiast

Jul 22, 2014, 8:48 PM

Post #5 of 35 (3024 views)
Re: [terrykhatri531] Need help to improve pagination [In reply to] Can't Post

Hi Terry,

If you want to use Perl to handle your pagination, don't try and write it yourself, the logic behind is a bit fiddly. As suggested previously, look into a module such as Data::Page, which has a very simple interface. There is also some support for generating the page links.

I understand you are now attempting to use javascript instead...


Quote
In the init function of jquery.simplePagination.js there is a variable hrefTextPrefix which is set to '#page-', which is no good for perl (right ?)


Is your concern that #page- would be treated as a Perl comment? It won't be a problem because jquery.simplePagination.js is a separate javascript file that is processed as javascript during HTML output.


Quote
so it does not work with my script and when I change it to '?page=' it does not go along with the javascript as it fails to read the URL to determine which page we are at.


Because the above should not be an issue, for now don't change the hrefTextPrefix until you know everything else works.


Quote
The 2nd problem is that the total number of pages is hardcoded in another js script called script.js which is


I haven't looked at jquery's simple pagination plugin, but there are numerous ways you could handle this, my choice would likely be to move the contents of script.js into your template (or print):


Code
<script src="script.js"></script> 

<script type="text/javascript>
$('#light-pagination').pagination({
pages: <TMPL_VAR NAME="pages">,
cssStyle: 'light-theme'
});
</script>


Let us know how you get on.

Chris


(This post was edited by Zhris on Jul 22, 2014, 9:04 PM)


terrykhatri531
User

Jul 23, 2014, 12:39 AM

Post #6 of 35 (3000 views)
Re: [recruiter] Need help to improve pagination [In reply to] Can't Post

Hi recruiter,

Thanks this is great but it has just Next and Back links, I would like to see it the way its shown in the picture attached in my first comment, I can see you are very good at perl, please why don't you try to use the jquery plugin attached and see how you make it to work with perl keeping in mind the 2 issues I have described above and comment made by Crhis, its simple to integrate with perl but I find it hard to make it to work precisely the way its supposed to.

Many many thanks.

Terry


terrykhatri531
User

Jul 26, 2014, 8:55 AM

Post #7 of 35 (2852 views)
Re: [Zhris] Need help to improve pagination [In reply to] Can't Post

Hi Chris,

The problem with jquery pagination plugin script is that when the page is reloaded the pretty counter gets reset to page 1 though the page may be at 103 and the whole logic in the jquery script is built around that counter therefore it does not work.



I know you have recommended DATA::Page before as well, but there are no examples included in the module and with that brief introduction I find it hard to use it and I do not see any examples of its being used on any forms in my search, if you have used it before do you mind sharing the code :)



A good monk at perlmonk has given me some code to do that the way I want it but I have to figure out how to add it to my script, if you can guide me that will be great !!

Here is the code :


Code
#!/usr/bin/perl --###### perltidy -olq  -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr -ce -nibc -i=4 -pt=0   "-nsak=*"#!/usr/bin/perl --use strict;use warnings;Main( @ARGV );exit( 0 );sub Main {    print join "\n", pageLinksHtml( 170, 11, 10, 5 );}sub pageNumbers {    return      { first => 1 },  9, 10,      { curr => 11 }, 12, 13,      { last => 17 },      ;} ## end sub pageNumberssub pageLinksHtml {    my( $total, $curr, $rate, $links ) = @_;    my @nums = pageNumbers( $total, $curr, $rate, $links );    for my $num ( @nums ) {        if( ref $num ) {            if( my $first = $$num{first} ) {                $num = sprintf '<li><a href="?;page=%d">{%d</a>...</li>',                  $first, $first;            } elsif( my $curr = $$num{curr} ) {                $num = sprintf '<li><b>%d</b></li>', $curr;            } elsif( my $last = $$num{last} ) {                $num = sprintf '<li>...<a href="?;page=%d">%d}</a></li>',                  $last, $last;            }        } else {            $num = sprintf '<li><a href="?;page=%d">%d</a></li>', $num, $num;        }    }    return '<ul>', @nums, '</ul>';} ## end sub pageLinksHtml


Many many thanks Chris for your great help that you have extended to me all the times, be rest assured it does not go unappreciated.

Rgds.

Terry


Zhris
Enthusiast

Jul 26, 2014, 2:27 PM

Post #8 of 35 (2845 views)
Re: [terrykhatri531] Need help to improve pagination [In reply to] Can't Post

Hi Terry,

Oh wow, you should break that single line of Perl code up so that its readable before you continue.

It looks like the foundations of what you need, but is far from a complete solution. The subroutine pageNumbers returns a list of values which are hardcoded, but you will need to programmatically generate these. The first, curr and last values can be gotten from Data::Page via the first_page, current_page and last_page accessor methods after instantiating the object with your known values, look at the synopsis, its a very straight forward module to use. The complicated bit will be working out what pages you want to display in between first / curr and curr / last, based on your design preferences and then testing that it works under different scenarios. The arguments $rate and $links look as though they were put in place as hints for this process.

Note that Data::Page isn't meant to be a complete pagination solution, it merely takes values you know i.e. total results, and calculates values you need to know i.e. total pages. Data::Pageset and Data::SpreadPagination are a little more in depth, in that they can be used to create the page navigation too, but I've never used and not sure if they can handle your exact design requirements.

Try and have a go at implementing yourself, start with a fresh script just to get your pagination working properly before implementing into your real world script, the base of it should be the code above. Hardcode the total results, results per page and current page number. If it works standalone then it is easier for us to run ourselves and advise you on issues. I don't have time right now to write up an example for you to work from, but am willing to work with you if you get something started.

Chris


(This post was edited by Zhris on Jul 26, 2014, 2:50 PM)


terrykhatri531
User

Jul 26, 2014, 3:48 PM

Post #9 of 35 (2837 views)
Re: [Zhris] Need help to improve pagination [In reply to] Can't Post


In Reply To
Hi Terry,

Oh wow, you should break that single line of Perl code up so that its readable before you continue.







Here you go :








Code
 
#!/usr/bin/perl --
##
##
## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr -ce -nibc -i=4 -pt=0 "-nsak=*"
#!/usr/bin/perl --
use strict;
use warnings;

Main( @ARGV );
exit( 0 );

sub Main {
print join "\n", pageLinksHtml( 170, 11, 10, 5 );
}

sub pageNumbers {
return
{ first => 1 }, 9, 10,
{ curr => 11 }, 12, 13,
{ last => 17 },
;
} ## end sub pageNumbers

sub pageLinksHtml {
my( $total, $curr, $rate, $links ) = @_;
my @nums = pageNumbers( $total, $curr, $rate, $links );
for my $num ( @nums ) {
if( ref $num ) {
if( my $first = $$num{first} ) {
$num = sprintf '<li><a href="?;page=%d">{%d</a>...</li>',
$first, $first;
} elsif( my $curr = $$num{curr} ) {
$num = sprintf '<li><b>%d</b></li>', $curr;
} elsif( my $last = $$num{last} ) {
$num = sprintf '<li>...<a href="?;page=%d">%d}</a></li>',
$last, $last;
}
} else {
$num = sprintf '<li><a href="?;page=%d">%d</a></li>', $num, $num;
}
}
return '<ul>', @nums, '</ul>';
} ## end sub pageLinksHtml


Rgds.

Terry


Zhris
Enthusiast

Jul 26, 2014, 4:40 PM

Post #10 of 35 (2832 views)
Re: [terrykhatri531] Need help to improve pagination [In reply to] Can't Post

Great, much more readable. Now work on that pageNumbers function and see how it goes.

Chris


terrykhatri531
User

Aug 1, 2014, 2:34 AM

Post #11 of 35 (2412 views)
Re: [Zhris] Need help to improve pagination [In reply to] Can't Post

Hi Chris, Ron and whoever can help,

Coming back to the javascript i.e. jquery.simplePagination.js attached to my initial commnet, I have had another look at it, the problem is on page reload or refresh the page slider returns to 1 because there is no functionality in the script to remember the position of slider on page reload, so as to make slider to remember its position after page reload we will have to add some routines to the javascript using a jquery cookie plugin (which is attached herewith).

There is an example on how to do that at http://stackoverflow.com/questions/14315459/how-to-use-the-jquery-cookie-plugin-to-make-jquery-remember-the-animations-after and I am sure from your experience you will know immediately what to add to that javascript to achieve what I want to do.

Chris, you seem to be very busy these days so whenever you have time PLEASE do have a look at it.

Thank you very very much !!

Terry
Attachments: jquery.cookie.js (3.05 KB)


Zhris
Enthusiast

Aug 1, 2014, 11:30 AM

Post #12 of 35 (2385 views)
Re: [terrykhatri531] Need help to improve pagination [In reply to] Can't Post

Hi Terry,

I have noticed from this and other posts that you are having difficulty in understanding how javascript fits in with your Perl code. Like HTML, javascript is client side code. You use Perl to generate the client side code, then its up to the client to handle i.e. apply stylesheet, run javascript etc. When your javascript is dynamic (i.e. relies upon your Perl variables), then firstly its easiest to move the relevant sections of the external .js file in with your main HTML, then secondly interpolate the Perl variables in the appropriate places just as you are already familiar in doing either via print or template.

The jquery pagination plugin you want to use has been mostly designed around dynamic fetching of results likely via ajax. One of the options you can supply is "onPageClick" where you can provide a custom handler to fetch the new set of results when a page button is pressed. However, this isn't necessary and you can simply supply the "items", "itemsOnPage" and "currentPage" options per request, which is the approach we will be following as I believe this is most suitable at this time.


Quote
the problem is on page reload or refresh the page slider returns to 1 because there is no functionality in the script to remember the position of slider on page reload, so as to make slider to remember its position after page reload we will have to add some routines to the javascript using a jquery cookie plugin.


This doesn't make much sense to me because position is dynamically put into the href for each page link for you to access. Its up to you to use the "hrefTextPrefix" and "hrefTextSuffix" options to design the href appropriately so that you can fetch this position in whatever manner you wish.

I have thrown together a standalone example for you to work from. Please note that I didn't spend much time on this, I have not looked into all of the plugins features, nor performed any testing. It is simply to put some of the concepts into practice.

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

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

my $items = 100;

my $cgi = CGI->new;

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

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

$template->param(items => $items);
$template->param(items_on_page => $items_on_page);
$template->param(current_page => $current_page);

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({
items: <TMPL_VAR NAME=items>,
itemsOnPage: <TMPL_VAR NAME=items_on_page>,
currentPage: <TMPL_VAR NAME=current_page>,
hrefTextPrefix: 'pagination.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>You are on page <TMPL_VAR NAME=current_page>.</p>
<div class="mypagination">
<p>error loading pagination.</p>
</div>
</body>
</html>


1) You describe that your root pagination function lives in a script called script.js. I have moved this into the template so that I can dynamically provide values derived in Perl to each option via template variables.

2) I have modified "hrefTextPrefix" so that when I click a page link, it makes a new request to my script with an appropriate query string containing the items on page and current page values.

3) I have not stored jquery or the plugin js / css on my server, instead have linked directly to external sources. You will want to adjust to point at your own library.

Finally, if you find this is not suitable and would like to revert to using the Data::Page method, then atleast try something out / post the code, then we can help you to get it working as desired. You still might need to use Data::Page to fetch the result range and perhaps aid you in sanitising user input i.e. current page must be an integer more than 0.

Regards,

Chris


(This post was edited by Zhris on Aug 1, 2014, 3:19 PM)


terrykhatri531
User

Aug 2, 2014, 1:56 AM

Post #13 of 35 (2308 views)
Re: [Zhris] Need help to improve pagination [In reply to] Can't Post

Thanks Chris for your assistance and the time you spent on it, problem is again with the slider which on reload does not maintain the state of botton no clicked and slides back to 1. See the picture attached where I am at page=15 but the slider is at 1, that's why I wanted to cookiefy the currentPage var so it should remember what slider button was clicked before page reload and after reload it should get the value from the cookie.

I am now asking around in jquery specific forums for help.

Thanks again.

Rgds.

Terry


(This post was edited by terrykhatri531 on Aug 2, 2014, 6:18 AM)
Attachments: SliderIssue.png (38.5 KB)


FishMonger
Veteran / Moderator

Aug 2, 2014, 7:14 AM

Post #14 of 35 (2300 views)
Re: [terrykhatri531] Need help to improve pagination [In reply to] Can't Post

It appears to me that you're spending a lot more time/effort trying to figure out this qjuery pagination than you would have spent figuring out how to use Data::Page or one of its brethren.


Zhris
Enthusiast

Aug 2, 2014, 8:37 AM

Post #15 of 35 (2288 views)
Re: [terrykhatri531] Need help to improve pagination [In reply to] Can't Post

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)


terrykhatri531
User

Aug 2, 2014, 9:56 AM

Post #16 of 35 (2279 views)
Re: [Zhris] Need help to improve pagination [In reply to] Can't Post


In Reply To

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

Code
 Thanks much Chris the whole script is attached herewith.Terry 
Attachments: vieword2.pl (7.66 KB)


Zhris
Enthusiast

Aug 2, 2014, 10:05 AM

Post #17 of 35 (2276 views)
Re: [terrykhatri531] Need help to improve pagination [In reply to] Can't Post

Hi Terry,

An issue I immediately notice is that you are again inconsistantly using param names i.e. the param name in your url is "page", but then you use cgi to fetch "current_page". Fix this first and see if it helps.


Code
my $current_page  = $cgi->param('current_page')  || 1; 
my $current_page = $cgi->param('page') || 1;


I will have another look through shortly and will post if I notice anything else suspicious.

Chris


(This post was edited by Zhris on Aug 2, 2014, 10:06 AM)


terrykhatri531
User

Aug 2, 2014, 10:13 AM

Post #18 of 35 (2270 views)
Re: [Zhris] Need help to improve pagination [In reply to] Can't Post

Great Chris !!! you are the man !!! That did the job, slider is now working the way its supposed to.

Many many thanks Chris for all your attention and time you always spend on fixing my issues !!! I am very appreciative of your help !

Rgds.

Terry


FishMonger
Veteran / Moderator

Aug 2, 2014, 10:18 AM

Post #19 of 35 (2268 views)
Re: [terrykhatri531] Need help to improve pagination [In reply to] Can't Post

Why are you creating 3 separate cgi objects?

You should only be using one.


Zhris
Enthusiast

Aug 2, 2014, 10:25 AM

Post #20 of 35 (2266 views)
Re: [terrykhatri531] Need help to improve pagination [In reply to] Can't Post

Glad it worked out.

But please please please consider spending time looking into using Data::Page to take care of the pagination calculations you are doing yourself i.e. offset and limit. Look at my example above...

There are some other issues with your code, but i'm sure you will pick up on these and fix if necessary.

Regards,

Chris


(This post was edited by Zhris on Aug 2, 2014, 10:26 AM)


terrykhatri531
User

Aug 2, 2014, 10:26 AM

Post #21 of 35 (2265 views)
Re: [FishMonger] Need help to improve pagination [In reply to] Can't Post

Thanks Chris I will fix that, there is one small issue with pagination, my code starts page with number zero i.e. 0 while slider starts with 1, please have a look at the picture, I will have look at the code but if you have quick fix that will be great.

Thanks again

Teryy


Zhris
Enthusiast

Aug 2, 2014, 10:29 AM

Post #22 of 35 (2261 views)
Re: [terrykhatri531] Need help to improve pagination [In reply to] Can't Post

I guess its because of the following calculation:


Code
my $first_page = $pagenum - $pagenum ; 

0 = 1 - 1;
0 = 10 - 10;
etc


Technically, the first page will always be 1, so my $first_page = 1; should be ok. Your other calculations could be invalid too. Heed my advise, let Data::Page do the hard work for you!

Quote from its documentation:

Quote
It has been said before that this code is "too simple" for CPAN, but I must disagree. I have seen people write this kind of code over and over again and they always get it wrong. Perhaps now they will spend more time getting the rest of their code right...


UPDATE: Also should be for my $i ($first_page .. $last_page).

Chris


(This post was edited by Zhris on Aug 2, 2014, 5:52 PM)


terrykhatri531
User

Aug 5, 2014, 2:13 AM

Post #23 of 35 (2057 views)
Re: [Zhris] Need help to improve pagination [In reply to] Can't Post

Thanks Chris,

I have found another jquery paginator and trying to configure it as follows, the line in red is causing the problem as it makes the paginator disappear off the web page :


Code
 
<div class="demo">
<div id="demo2">
</div>
</div>

<script src="js/jquery.paginate.js" type="text/javascript"></script>
<script type="text/javascript">
\$(function() {

\$("#demo2").paginate({
count : $pagenum,
start : $current_page,
onChange : function('vieword2.pl?page='){return true;},
display : 28,
border : false,
text_color : '#888',
background_color : '#EEE',
text_hover_color : 'black',
background_hover_color : '#CFCFCF'
});
});
</script>




Here is the relevant code piece from the jquery :


Code
 
$.fn.paginate.defaults = {
count : 5,
start : 12,
display : 5,
border : true,
border_color : '#fff',
text_color : '#8cc59d',
background_color : 'black',
border_hover_color : '#fff',
text_hover_color : '#fff',
background_hover_color : '#fff',
rotate : true,
images : true,
mouse : 'slide',
onChange : function(){return true;}
};




The help on the web site says :

onChange: The callback function when clicking on a page. As argument the number of the page clicked can be used.



The plugin is attached herewith, please when you have time do have a look at it.

Many many thanks !!

Terry
Attachments: jPaginate.zip (76.2 KB)


Zhris
Enthusiast

Aug 6, 2014, 11:34 AM

Post #24 of 35 (1958 views)
Re: [terrykhatri531] Need help to improve pagination [In reply to] Can't Post

Hi Terry,

Your javascript issues would be better suited on a javascript / jquery forum, you will likely receive a better response.

From briefly looking over the documentation, it looks as though there is no way to supply a href format via the options available, instead you must rely on the onChange handler. If you want a similar non ajax approach as above, then perhaps just simulate the click. Untested:


Code
onChange : function(page) { window.location.href = 'vieword2.pl?page=' + page; }


Chris


terrykhatri531
User

Aug 6, 2014, 11:42 AM

Post #25 of 35 (1955 views)
Re: [Zhris] Need help to improve pagination [In reply to] Can't Post

Great thanks Chris, I did post it on a jquery forum too and I got the similar code i.e.


Code
  1. onChange : function(page){
  2. location.href = 'vieword2.pl?page=' + page;
  3. }



Thanks very very much !! Appreicate it.

Regards

Terry

First page Previous page 1 2 Next page Last page  View All
 
 


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

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