yii relational datagrid widget
Using Yii's CGridView widget I want to show data from two or more DB tables in a data grid like
display orders and customers information in dataGrid using widget
Any Idea?
Thanks in advance.
You can display related data by using the relations attributes of the model and the 'value'/'filter' attributes of CGridView's columns. For instance, assume that each order has a 'customer' relation defined in the model's relations read-only attribute. You could easily display information from both tables as such, assuming that $model is a search instance of your order model.
$this->widget('zii.widgets.grid.CGridView',array(
'id' => 'order-grid',
'itemsCssClass' => 'dataGrid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
'order_number',
array(
'name' => 'customer_id',
'value' => '$data->customer->first_name . " " . $data->customer->last_name',
'filter' => Html::listData(Customer::model()->findAll(),'id','name'),
),
...
));
This assumes that you want to use a drop-down as the filter. There are other filters you can use, or you can hack in custom filtering to your dataProvider method.
链接地址: http://www.djcxy.com/p/69720.html上一篇: Yii自定义Widget,加载器错误
下一篇: yii关系数据网格部件