Saturday, November 28, 2009

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

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.organd 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<cake-php%2Bunsubscribe@googlegroups.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 at http://groups.google.com/group/cake-php?hl=en

No comments: