Need design help ajax+controller, sorting, filtering

Hello community,

i need an advice in how to design the following problem:

I have a list, no grid or something, generated from an action, e.g /site/action/10

That action generates a list with all entries where id= 10. These entries are presented in <div> containers on my site.

Now i want to add some ajax sort and filter features to sort or limit the list (in detail: sorting by price and/or filter by price between 5 and 10, …).

My first Idea was to create a FilterController, which handles the actions from the different ajax sort/filter links, like a CDbCriteria builder class.

Then in the controller where the list gets generated, i check if there was some sort/filter stuff build and add it to the query.

But then i’ll have to call the action to display the list from the FilterController and i think thats not the right way how to do it.

Thanks in advance,


Hi sbr, welcome to the forum.

You’d be better consider using a CListView for your needs.

Please have a look at this wiki:

hi, thanks for your response.

yes i thought so, but am i able to filter with CListView, like "field BETWEEN 1 AND 5"?

i need to dynamically change the dataProvider for that, and thats where my actual problem is, i guess?


Hi sbr,

Yes you are. :)

As you may see in the wiki, you can replace the CGridView of gii-generated admin page with a CListView, where you can use ‘Advanced Search’ form to filter the list items.

First, add some attributes(public properties) to your model for those filtering parameters.

And then create a customized search() method in the model to return the CActiveDataProvider for the list.

Note that the ‘Advanced Search’ form uses an instance of the model, and it is meant for the container of the search parameters.

Nice, i’ll give it a try!