Reputation: 1069
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...
Upvotes: 0
Views: 1293
Reputation: 965
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
Upvotes: 1
Reputation: 51
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);
}
Upvotes: 0