Search form and CGridview

This is probably a dumb question and perhaps I am misusing Cgridview.

I can’t figure out how to search Gridview with a form. I know how to use the search feature in the grid itself, and I know how to setup CActiveDataProvider with criteria to send the right data to the grid in the first place… but I can’t figure out how to have a search form whose fields are not necessarily shown in gridview!


I want to have a search form that will let me search fields that I am not necessarily displaying in the grid. Therefore, I can’t use the advanced search thing and I can’t use grid filters.

When I tried to implement this the first time I can get the grid to show up but any attempt to sort / paginate / filter the grid results in the grid going away. This is a surprisingly hard thing to search for an answer to because the words grid and search are so common. Just looking for a step in the right direction, or a suggestion of a better way to acheive what I’m trying to do.

Hi, dniznick

Do you mean that the fields that you want to search are not included in the database columns?

Or are they just excluded from the grid display?

Included in the database but not part of the grid. I want to search on columns I am not displaying.

I did a bunch of reading on this last night and it indeed looks like a stupid question. I need to study the ‘advanced search’ that gii automatically generates for admin views a little more.

For starters I need the form to submit via GET instead of POST.

It also occurred to me that the columns I want to search but not display need to be selected in the activeDataProvider. Still getting used to using those and I had been using ‘select’ to limit the columns returned.

Yes, that’s exactly the point I wanted to tell.

I usually start with a gii-generated "admin" page to create some customized "search" page.

  1. Hide unnecessary columns from the grid.

  2. Bring out the "advanced search" form to the front.

  3. Delete unnecessary fields from the "advanced search" form.

  4. etc.

This approach has always been successful for me.

i want to put the search form for all model which the user can choose on the site index page… anybody have idea how to do that and how we can manipulate the admin gii generated page for that purpose…

I’d rather use Google Custom Search for that purpose.

So I figured it out. Mostly I was POSTing instead of GETting and wasn’t thinking it through.

Search form + gridview makes me happy!