0
votes

Situation: I created a kind of wizard with a CGridView at the bottom. Every time the user selects something in the wizard, the grid will be "filtered" (without AJAX) by the model its search function. I keep all the user his "answers" of the previous steps in hidden fields, so I can use them every step in my wizard again for filtering.

Problem: When I sort or filter directly in the cgridview (with the default filter fields and sorting titles), he doesn't use my hidden field values anymore. I'm probably a bit lost (I'm pretty new to YII btw). How can I give the default filter and sort requests the values of my hiddenfields, so they will be used in the search function? I can see that I need to add params like for example Person[name] to the request, but I don't know how...

2
The hidden fields you added, are they also in the form ModelName[AttributeName] ? Yii is pretty strict about those in its widgets & using them. It might be best if you specify some more information (code etc), you're giving the people here little to go on. - Blizz
Thanks, I don't want to make this question to specific (that's why I have no code), because i think its a common problem. Imagine I have my own form (not a widget) above my cgridview. A user can fill in some fields in my custom form. The moment the user filters or sorts the CGridView (with the default buttons and fields), the sorting or filter action needs to use the values of my custom form also. Actually I want to make something like the Advanced search form, but that one is a nice piece of complicated code to understand :). Hope this makes more sense... - Wannes

2 Answers

1
votes

You can solve this by changing inputSelector variable in jquery.yiigridview.js

For example, by changing it like the following you can define your input fields as gridview internal fields by adding filterClass (witch default value is filters) to your input fields

inputSelector = '.' + settings.filterClass + ' input, ' + '.' + settings.filterClass + ' select';

EDIT: in Yii 1.1.13 filterSelector attribute has been added to CGridView that does the job

0
votes

Here are my 4 and a half cents....

The only way I see this working is that you store your "wizard" values via the non-AJAX submit process somewhere (I'm thinking $_SESSION but have no idea if that will work) that can be accessed by the model->search() function which is called in all instances of filtering/searching and add them there to the search criteria.

Obviously the following does not help you but might explain a bit more what I did in a similar situation. I was wanting to by default limit the view of a large table for certain types of users, but the limitation was not as straight forward as only showing entries for a single user id. As soon as the user would filter the data they had access to all of the underlying data in there.

What I ended up doing was detecting if they had filtered on any of the columns I was using to limit the data and applying the user submitted filter if so or applying my own limitation filter on the same column if they hadn't. So for each column that I would want to apply this to I would do something like this inside the model->search() function along with detecting if this default limitation should apply or not for the user in question:

if(isset($this->A_DB_Column_Name) && in_array($this->A_DB_Column_Name,array(default limitation))) {
    $criteria->compare('A_DB_Column_Name',$this->A_DB_Column_Name,false);
} else {
    $criteria->compare('A_DB_Column_Name',array(default limitation),false);
}