For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > January 2007 > Re: [PEAR] Structures_DataGrid_Renderer_Pager: showing the page that









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PEAR] Structures_DataGrid_Renderer_Pager: showing the page that
Olivier Guilyardi

2007-01-10, 8:04 am

Hi Sylvain,

Sylvain Beucler wrote:
> I'd like to do use Structures_DataGrid to show a list of data entries,
> with a Pager to show those entries split on several pages, and be able
> to select a page by saying "show me the page that contains data X".


Interesting point. One of the most useful example IMO is a select box as shown
here: http://groups.google.com/groups/dir?hl=en&sel=33554433
(I talk about the "Usenet" dropdown: "1 ... ar", "arc ... bit", etc...)

> Sample use cases: you show a list of users (thousands of users) using
> Structures_DataGrid, and with the Pager renderer, 20 users per page.


I assume you're just talking about user management as an example. But if that's
really your purpose, I believe the best thing could be to make a new
Structures_DataGrid_DataSource_LiveUser driver.

> - when you click on a user, you go to the user's edition page, and
> there, the same Structures_DataGrid array shows the page that
> contains the user you're editing (instead of getting back to the
> first page).


This is easy to do.

> - show entries "starting with" a given one. E.g.: there's a search box
> in the users list page where you can type a username's first letter
> in. If you type 'B', then you show the list of users starting with
> 'B', but then also the users starting with 'C' if there's still room
> for it, then 'D', etc. I mean: do not just restrict the data input
> to users starting with 'B' - if there's only 1 such users a
> one-liner array will look a bit weird.
>
> For SQL, I guess this would require a quick query to know the position
> of a given element according to the current sorting constraints
> (SELECT COUNT(*) FROM my_users_table WHERE login_name < 'B' ORDER BY
> login_name DESC...) and adapt the LIMIT accordingly.


For this simple alphabetic condition, I thing there's no need for an additionnal
query. One query should be sufficient:
SELECT * FROM my_users_table WHERE login_name >= 'b' ORDER BY login_name ASC;

However, for the google example mentioned above, a scanning query is obviously
needed.

> Is there a way to do that with Structures_DataGrid? Otherwise, could
> this make a feature request, or is the package architecture just not
> meant for that?


Structures_DataGrid does not yet provide such a neat feature. But it's precisely
its purpose to provide that kind of thing.

The package architecture is meant for it, however it is a work in progress. Your
idea would for example need something like the filter() method mentioned in TODO 19:
http://cvs.php.net/viewcvs.cgi/pear....21&view=markup

Then you should write a new renderer driver which job is strictly to render such
filtering forms.

Feel free to help us on this issue, a feature request, especially if it contains
a patch, would be greatly appreciated ;)

Regards,

--
Olivier
Olivier Guilyardi

2007-01-15, 7:02 pm

Hi,

Mark Wiesemann wrote:
> Sylvain Beucler wrote:
> [...]
>
> Actually I think that SDG is already able to do what you want it to do.
> If I got your idea right, you just need to follow my pointer on the code
> of the PEAR account list page, calculate the right page yourself, and
> pass this value to the SDG constructor.


Mark, I think the page argument of the SDG constructor is not sufficient for
Sylvain, because he wants to 'show entries "starting with" a given one'.
Example: display 10 rows per page, the B letter starts at row 15 ; with the page
argument he can only starts from a multiple of 10.

So IMO, Sylvain you should simply bypass SDG page handling :

$datagrid = new Structures_DataGrid();
$start = <compute at which row you want to start>
$datagrid->bind("SELECT foo FROM bar LIMIT $start, 10");

And don't use the default Pager renderer, write your own "letter" driver.

Regards,

--
Olivier
Mark Wiesemann

2007-01-15, 7:02 pm

Hi Sylvain,

Sylvain Beucler wrote:
> Yeah, that's the main problem: computing the appropriate page means I
> have to recompute what SDG does, taking into account the sort field,
> sort order and pager size, which I think SDG should do. I don't so
> much look for how to program it than how to have my data-display lib
> do it automagically.
>
> Given the versatile nature of SDG I wondered if that value->page#
> mapping is a wanted feature - I think getting the positionning for a
> SQL query needs non-trivial rewriting (self-join) or inefficient
> full-length prescanning; moreover other structures SDG reads from
> might just not be suitable. On the other hand this would be a nifty
> addition.
>
> If I understand well this is not a wanted feature and users should
> just manually precompute and set the appropriate page. Too bad!


I'm still not sure what your real request is, as your descriptions
aren't clear about that.

Do you want to have (e.g.) 15 records on every page and additional
alphabetic paging links, just like PEAR's account listing works? [1]

Or do you "just" want alphabetical paging, e.g. with 13 records
beginning with "A" (= first page), then 27 records beginning with "B" (=
page 2), ..., then 5 records with "Z" (= last page)?

IMO the first variant needs just an additional paging renderer that does
the computation. The second variant would be very complex and would
require many internal changes in Structures_DataGrid.

If both variants are not your idea, then please describe it with some
more details or examples.

Regards,
Mark

[1] http://pear.php.net/accounts.php

--
http://www.markwiesemann.eu
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com