YiiFramework development tutorial Zii component-GridView example
Source: Internet
Author: User
CGridView displays data in a table. CGridView also supports paging and sorting. the most basic usage and ListView type of CGridView are dataprovider, usually CActiveDataProvider. Modify the previous YiiFramework development tutorial (31 )... 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 Yii Framework Development Tutorial (31) Zii component-DetailView example, and set ListView to GridView: [php] Widget ('zii. widgets. grid. CGridView ', array ('dataprovider' => $ dataProvider, 'ajaxupdate' => false, 'template' => '{pager} {summary} {items} {pager}',);?> 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. Redefine the columns attribute of the GridView as follows: [php] 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 ))) ',),' Compa Ny ', array ('class' => 'clink', '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? ',);?> 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 ('C Lass '=> 'clink', '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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.