Building Example Pager Class
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
I was thinking of supporting the URL generation and request processing part to maintain and reverse the current sort direction. That's the useful part as it relates to the Pager.
I don't know the specifics, but assumed that you would initialize sorting by providing some kind of array of the fields you want to be possibly sorted on (like you presented). The database side is easier because "ORDER BY" is standard -- unlike generating record sets.
I don't know the specifics, but assumed that you would initialize sorting by providing some kind of array of the fields you want to be possibly sorted on (like you presented). The database side is easier because "ORDER BY" is standard -- unlike generating record sets.
(#10850)
I've never said that afterwards they can easily be combined.. When i decided to stop passing arrays with data, but instead "pageable data (whatever that may be) i had the following in mind...
1-) You start with a SortableAndPageableSQLQueryDataSource (atleast it's clear what it is :p)
2-) Order the data by using the methods of the Sortable interface (add an ORDER BY clause (or whatever that is needed))
3-) Page the data by using the methods of the Pageable interface (add a LIMIT clause (or whatever that is needed))
4-) Then you "render/display" the data.. A SortablePageWriter should know how to generate links for sorting and paging.
5-) Time for a couple of beers...
1-) You start with a SortableAndPageableSQLQueryDataSource (atleast it's clear what it is :p)
2-) Order the data by using the methods of the Sortable interface (add an ORDER BY clause (or whatever that is needed))
3-) Page the data by using the methods of the Pageable interface (add a LIMIT clause (or whatever that is needed))
4-) Then you "render/display" the data.. A SortablePageWriter should know how to generate links for sorting and paging.
5-) Time for a couple of beers...
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
I was thinking:
1) Time for a couple of beers...
2) Add the ability to register fields to sort on
3) Figure out how to maintain sort direction internally
4) Add a method to create URLs for changing the sort order
5) Add code to get sorting parameters from the request
6) Maybe add an OrderBy() method to the Pagable classes
1) Time for a couple of beers...
2) Add the ability to register fields to sort on
3) Figure out how to maintain sort direction internally
4) Add a method to create URLs for changing the sort order
5) Add code to get sorting parameters from the request
6) Maybe add an OrderBy() method to the Pagable classes
(#10850)
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Adding onclick?
Hi,
I just came across your great class. I would like to you it for Ajax based pagination. How would I go about adding something like this:
onclick="ajaxPaging($var1, $var2, $page);return false;"
Thanks!
I just came across your great class. I would like to you it for Ajax based pagination. How would I go about adding something like this:
onclick="ajaxPaging($var1, $var2, $page);return false;"
Thanks!
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
That's a great idea. There are probably a couple of ways to do it. The application specific way would be to create one wrapper that accepted calls and another that put the page data into XML/JSON/whatever as a response. But it would be easier to have the library handle that as well because the whole point of a Pager class is to deal with all the annoying details of pagination. It seems like the XML response should contain the page data, plus info for the paging display. Then on the Javascript side we could have code to parse the XML and return the data as an array and set the paging variables at the same time.
What did you see the code looking like? You showed:
I guess we would need similar calls in Javascript to the current PHP interface, such as ajaxPage, ajaxPageNext, ajaxPagePrev, ajaxFirst, ajaxLast, ajaxRange, etc.
I would be interested to know what you (and others) think the Javascript interfaceshould look like.
FYI - I have continued to develop that code and may have a newer version with more features than the one you are looking at.
What did you see the code looking like? You showed:
Code: Select all
onclick="ajaxPaging($var1, $var2, $page);return false;"I would be interested to know what you (and others) think the Javascript interfaceshould look like.
FYI - I have continued to develop that code and may have a newer version with more features than the one you are looking at.
(#10850)
Hi arborint,
I'm currently using a pagination class called PaginateIt, http://www.bradyvercher.com/, that only produces the pagination links. Therefore the data is displayed independently. However, I had to make some mod's to pass in the javascript function and parms as a string. Not the nicest solution but it works. I'm also using xajax, so I won't require the Json/XML. But I'm just being selfish! People who are using the Pager class may want it
Here's an example of the link would look like:
I have the href stuff just in case users don't have javascript enabled.
Sorry, it's late - hopefully this makes sense
I'm currently using a pagination class called PaginateIt, http://www.bradyvercher.com/, that only produces the pagination links. Therefore the data is displayed independently. However, I had to make some mod's to pass in the javascript function and parms as a string. Not the nicest solution but it works. I'm also using xajax, so I won't require the Json/XML. But I'm just being selfish! People who are using the Pager class may want it
Here's an example of the link would look like:
Code: Select all
<a href="/products/?cat=1&pid=1&page=2" title="goto page 2" onclick="xajax_pageNavigate(1,1,2);return false;">2</a>Sorry, it's late - hopefully this makes sense
With regards to including functionality such as ordering and so forth, should that not be a seperate entity/class to the pager class?
I can just see this pager class, as awesome as it will be/is, being blob like with lots of functionality that is only rarely used, weighing down the objects. So would it be better to seperate the classes out as per functionality? You could also argue that the ordering should be done by the datasource/dataobject before being passed to the pager?
Likewise for the iteration of pageable data, shouldn't the pager class return the pages data in bulk, and a seperate iterator (be it a template system's iterator such as smarty {section}) handle the.. iteration?
I can just see this pager class, as awesome as it will be/is, being blob like with lots of functionality that is only rarely used, weighing down the objects. So would it be better to seperate the classes out as per functionality? You could also argue that the ordering should be done by the datasource/dataobject before being passed to the pager?
Likewise for the iteration of pageable data, shouldn't the pager class return the pages data in bulk, and a seperate iterator (be it a template system's iterator such as smarty {section}) handle the.. iteration?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Hi Jenk,Jenk wrote:With regards to including functionality such as ordering and so forth, should that not be a seperate entity/class to the pager class?
I can just see this pager class, as awesome as it will be/is, being blob like with lots of functionality that is only rarely used, weighing down the objects. So would it be better to seperate the classes out as per functionality? You could also argue that the ordering should be done by the datasource/dataobject before being passed to the pager?
Likewise for the iteration of pageable data, shouldn't the pager class return the pages data in bulk, and a seperate iterator (be it a template system's iterator such as smarty {section}) handle the.. iteration?
Are you talking about my pager code or the one referenced by DragonI above?
In my pager code things are pretty split out, but if you think more could be done I would like to do it. The breakdown as is recall is a follows. There is a core Pager class that maintains and calculates values. The datasource object are completely separate and only provide the Pager with maximim values -- you build the list of items yourself. Also the HTML generator for the paging links is a separate class gets its data from a Pager object passed to it, so you can build your own HTML writer if you like.
(#10850)
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
I am not sure what Tim and I were talking about -- I know he was (and always is) very helpful to me in these types of discussions. The Pager I ended up implementing is in four main parts:Jenk wrote:sorry, I was referring to the discussion between yourself an timv at the top of this (5th) page
I got the impression it was all going into one class, if it's not that's fine by me :p
1. The Pager class that is a container to hold all the associated values and where the paging calculations occur.
2. Request classes (there are two, with and without sessions) that process the request and sets values in the Pager object based on what the user clicked
3. A HTML writer class that uses the data in the Pager object to generate the HTML paging links
4. Small data source classes for several database types and arrays. These provide the pager with the total number of records and can fetch a page of rows -- you supply the SQL query.
My goal was to separate the various parts of paging into separate classes to make it database independent and allow custom HTML building of pages. I also wanted some features I use for CRUD pages which allow the pager to remember which page it was on when returning up from a Create/Edit page.
Based on DragonI idea to do an Ajax addon, I think I would need to split the HTML Writer into a PHP XML Writer class to provide the feed and a Javascript HTML link builder. That sould not me too hard as everything is separated.
I has been a while looked closely at the code and anyone who wants to review/refactor it would be appreciated. The code is available here:
http://ap3.sourceforge.net/
(#10850)