Hello Lebowski, welcome to the forum.
CGridView is a very powerful widget, and it will help you very much. So I think you are on the right track when you are starting with it.
And in addition, reading the generated HTML code of the admin page will help you understand the grid a lot.
1: First, it creates an instance of a model in actionAdmin.
It is not meant for the container for the data to be displayed in the grid. It’s a holder of the search parameters.
2: Clear the contents of the model instance to give it the default empty search parameters.
3: Check to see if $_GET[‘Model’] is defined. When it’s the first time around, $_GET[‘Model’] will not be defined.
4: If $_GET[‘Model’] is defined, then it means that the action has been called from the admin view with some search parameters defined. Then we will set the search parameters to the model attributes according to $_GET[‘Model’].
5: Render an admin view passing the model instance with the name of ‘model’.
6: In the view, the CGridView widget will be created with the ‘dataProvider’ property set as ‘$model->search()’. That means the search() method of the model will create a data provider and give it to the grid. When the instance of that model is empty (that is the case when it’s the first time around), then all the data will be displayed in the grid. But when it has something defined, for example, $model->company_name is defined (that can be the case when the action was called the 2nd time and after), then search() method will create some WHERE clause to filter the search results according to the attributes, and eventually the grid will show you the filtered results.
7: Also in the view, a form for ‘advanced search’ will be created. Each field of the form has a ‘name’ in the format of “Model[attribute]”, so that the form can send back and forth the search parameters contained in the model instance to the admin action.
See how the CActiveForm is used to create the search form using the model in ‘_search.php’.
8: Usually the CGridView also has a property ‘filter’ set to the model. It’s roughly equivalent to the model usage in the advanced search form. It will create the header filter fields with the same naming convention.
There are more things to learn about the grid, pagination and sorting, for example.
But understanding the basic structure stated above will surely be a help, I hope.