Saturday, November 28, 2009

RE: How to paginate with user-selected filter-options?

I had the same problem and used the same method. Save to session and check
session. Also not sure if this is the best way but it works.

-----Original Message-----
From: DigitalDude [mailto:e.blumstengel@googlemail.com]
Sent: November-28-09 3:40 PM
To: CakePHP
Subject: Re: How to paginate with user-selected filter-options?

Hey,

ok I found a way to do this, but I'm not sure if that's the right approach.

What I'm doing now, is store the incoming filter-options in the Session.
When a user comes into the controller for the first time, I check if the
session-keys are set, and if not, I apply some standard options. When the
user sends the form, I write the selections into the session, and then set
my variables with these session values. This works perfectly, even when I'm
on page 2 and use the column-sorting everything is displayed correctly.

I don't know if this is absolutely correct, but it works and I'll further
develop this if anyone can tell me a better way to do this...

Regards,

DD

On 28 Nov., 19:42, DigitalDude <e.blumsten...@googlemail.com> wrote:
> Hey,
>
> I tried, but it won't work. The variables für limit, order and sortby
> are overwritten after I change the page of the pagination, because the
> date from the forms no longer exist and are overwritten by my standard
> values.
>
> The problem is that when I use my filter-form and send the form, the
> variables are set. But when the paginator-link is clickes, the
> controller is called again, variables are set and the RequestHandler
> part will be ignored because in this case the data from the forms is
> not given to the controller.
>
> So I guess I need a way to
>
> a) store the given form data (filter options) persistent in my app so
> it won't be overwritten after a page-change
>
> or
>
> b) manipulate the links of the form helper after sending the form so
> it will have the desired options I selected in my form...
>
> There has to be someone who already did this in an app, right....?
>
> On 28 Nov., 19:33, Dave <davidcr...@gmail.com> wrote:
>
> > Rather then using request handler to check for post, you can try
> > just checking if the value exists, ie
>
> > if(!empty($this->data['Professor']['limit'])) $limit =
> > $this->data['Professor']['limit'];
>
> > On Sat, Nov 28, 2009 at 1:16 PM, DigitalDude
> > <e.blumsten...@googlemail.com>wrote:
>
> > > Hey,
>
> > > I know how the paginator works and how I can define my conditions
> > > to filter as I like, but I was wondering how to add some more
> > > usability to this so let's say the user should set the filters "on
> > > the fly" with some drop downs...
>
> > > So I made some dropdowns with some options such as order =>
> > > ASC/DESC, limit => 5,10,20,50 and oderby =>
lastname/firstname/email...
>
> > > That's really easy I think, so I created this as a form on top of
> > > the index-table, and checked in my controller wether the form is
> > > sent or not.
>
> > > The options I selected with my dropdowns are set and when I see
> > > the pagination after I hit "Sent!" the table is sorted as I selected
it.
>
> > > But now comes the problem:
> > > After I hit "Page 2", my filters are overwritten by the default
> > > values of my controller. So I think I'm doing something wrong, and
> > > I need a simple example of how I can achieve the desired
functionality.
>
> > > Could please someone give me a hint how I can do it? When I hit
> > > the page-change link, my selected values are overwritten beause
> > > the RequestHandler does not kick in.
>
> > > Here's my controller-code:
>
> > > public function myProfs() {
> > >        $limit = 10;
> > >        $order = 'ASC';
> > >        $sortby = 'lastname';
> > >        if($this->RequestHandler->IsPost()) {
> > >            $limit = $this->data['Professor']['limit'];
> > >            $order = $this->data['Professor']['order'];
> > >            $sortby = $this->data['Professor']['sortby'];
> > >        }
> > >        $this->paginate['Professor'] = array(
> > >            'contain' => false,
> > >            'conditions' => array(
> > >                'Professor.deleted' => 0,
> > >                'Professor.user_id' => $this->Auth->User('id')
> > >            ),
> > >            'limit' => $limit,
> > >            'order' => array(
> > >                'Professor.'.$sortby => $order
> > >            )
> > >        );
> > >        $limits = $this->Professor->getItemCount();
> > >        $orders = $this->Professor->order();
> > >        $sortbies = $this->Professor->sortBy();
> > >        $professors = $this->paginate('Professor');
> > >        $this->set(compact('professors', 'limits', 'orders',
> > > 'sortbies')); }
>
> > > Regards,
>
> > > DD
>
> > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp
> > > others with their CakePHP related questions.
>
> > > You received this message because you are subscribed to the Google
> > > Groups "CakePHP" group.
> > > To post to this group, send email to cake-php@googlegroups.com To
> > > unsubscribe from this group, send email to
> > > cake-php+unsubscribe@googlegroups.com<cake-php%2Bunsubscribe@googl
> > > cake-php+egroups.com>For more options, visit this group at
> > >http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others
with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com To
unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group
cake-php+at http://groups.google.com/group/cake-php?hl=en
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.709 / Virus Database: 270.14.83/2526 - Release Date: 11/28/09
04:15:00

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: