CGridView displays data in a table. CGridView also supports paging and sorting. The most basic usage and ListView type of CGridView are through data provider, usually CActiveDataProvider. Modify the previous example Yii Framework development tutorial (31) Zii component-DetailView, and set ListView to GridView: [php] <? Php $ this-> widget ('zii. widgets. grid. CGridView ', array ('dataprovider' => $ dataProvider, 'ajaxupdate' => false, 'template' => '{pager} {summary} {items} {pager}',);?> <? Php $ this-> widget ('zii. widgets. grid. CGridView ', array ('dataprovider' => $ dataProvider, 'ajaxupdate' => false, 'template' => '{pager} {summary} {items} {pager}',);?> The result is as follows: All fields are displayed by default in the GridView, and fields are displayed in the default format. To control the field display and format, you can configure the CGridView :: columns attribute. Each column in The GridView is a CGridColumn object. CGridColumn is the base class of all Grid list items. Each table can have a header, multiple data units, and an optional table's tail cell. CButtonColumn indicates that the cell is one or more buttons. By default, three buttons, "view", "update", and "delete", are displayed. You can change them by setting the buttons and template. CCheckBoxColumn indicates that the cell is Checkbox and supports read-only, single-choice or multiple-choice. By configuring selectableRows, CDataColumn indicates that the cell is a data or expression. By configuring name or value, the former indicates the attribute name of the data model, and the latter code is a PHP expression. CLinkColumn indicates a hyperlink. You can set the link by configuring label, url, or imageUrl. The columns attribute of the GridView is redefined as follows: [php] <? Php $ this-> widget ('zii. widgets. grid. CGridView ', array ('id' => 'person-grid', 'dataprovider' => $ dataProvider, 'htmloptions' => array ('style' => 'width: 740px '), 'pager' => array ('maxbuttoncount' => '7',), 'columns' => array ('header' => 'name ', 'type' => 'Raw', 'value' => 'chtml: link ($ data-> FirstName. "". $ data-> LastName, $ this-> grid-> controller-> createUrl ("view", array ("CustomerId" => $ data-> CustomerId )))' ,), 'Company', array ('class' => 'bucket', 'header' => 'email ', 'imageurl' => 'images/email.png ', 'labelexpression' => '$ data-> Email', 'urlexexpression' => '"mailto ://". $ data-> Email ', 'htmloptions' => array ('style' => 'text-align: Center '),), array ('class' => 'cbuttoncolumn', 'deleteconfirmation '=>' Are you sure to delete this item? ',);?> <? Php $ this-> widget ('zii. widgets. grid. CGridView ', array ('id' => 'person-grid', 'dataprovider' => $ dataProvider, 'htmloptions' => array ('style' => 'width: 740px '), 'pager' => array ('maxbuttoncount' => '7',), 'columns' => array ('header' => 'name ', 'type' => 'Raw', 'value' => 'chtml: link ($ data-> FirstName. "". $ data-> LastName, $ this-> grid-> controller-> createUrl ("view", array ("CustomerId" => $ data-> CustomerId ))) ',), 'Company ', Array ('class' => 'bucket', 'header' => 'email', 'imageurl' => 'images/email.png ', 'labelexpression' => '$ data-> Email', 'urlexexpression' => '"mailto ://". $ data-> Email ', 'htmloptions' => array ('style' => 'text-align: Center '),), array ('class' => 'cbuttoncolumn', 'deleteconfirmation '=>' Are you sure to delete this item? ',);?> Shown as follows:
Click the name to display the DetailView. The update, search, and delete operations of ButtonColumn are not added with the corresponding view.