Re: Structures_DataGrid_Renderer_Pager: showing the page that contains a given entry
| From: | Sylvain Beucler | Date: | Wed, 10 Jan 2007 13:45:21 +0000 |
| Subject: | Re: Structures_DataGrid_Renderer_Pager: showing the page that contains a given entry | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-26310@lists.php.net to get a copy of this message | ||
On Wed, Jan 10, 2007 at 12:50:51PM +0100, Olivier Guilyardi wrote:
> 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/Structures_DataGrid/TODO?revision=1.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 ;)
Thanks for your answer.
My aim is not filtering though. The SQL query you mention removes
every user whose name starts with 'a'. I'd like them to appear before
the 'b' usernames if there's room for it, so I can see the users
'surrounding' mine.
Another example is bills management: let's say I enter lots of bills
my company received, each of which gets an ID (auto_increment,
etc.). Then I want to go to "Bill #6152", a number I can type in a
simple form I'll manually process. The app should show that bill for
edition and, below, the pager. The pager will be placed on the page
that contains bill #6152, as if I had clicked on the right page number
directly. This also means that the "previous page" link will still be
valid. If I had filtered bill_id >= 6152, then bill #6152 would be the
first item of the data set and there would be no "previous page" link.
So if bill #6152 is on page 10, then I'd like that, when editing that
bill, the pager would automatically switch to page 10 (using bill_id
as a contructor parameter or something) of the full pager (not a
subset of the data source).
Being able to select a page using the first letters of the data
instead of a page number (your example from Google) is related to that
feature, but is not the same thing. I'm looking for a way to
programmatically select the appropriate page from its content.
Alternatively it would be ok to have to pager start with bill #6152
(which is different than clicking on page 10, if #6152 is not the
first entry of page 10) but still provide a valid "previous page"
link.
I hope I managed to explain what I have in mind ;)
--
Sylvain