Changes
Title
unchanged
multiple CActiveDataProviders in one CGridView
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
multiple, CActiveDataProvider, CGridView, in one, CArrayDataProvider
Content
changed
[...]
```php
$prov1 = new CActiveDataProvider('Post', array(
'criteria' => array(
'condition' => 'id<3'
)
)
));
$prov2 = new CActiveDataProvider('Post', array(
'criteria' => array(
'condition' => 'id>3'
)
)
));
```[...]
```php
$records = array();
for ($i = 0; $i < $prov1->totalItemCount; $i++) {
$data = $prov1->data[$i];
array_push($records, $data);
}
}
for ($i = 0; $i < $prov2->totalItemCount; $i++) {
$data = $prov2->data[$i];
array_push($records, $data);
}
$provAll = new CArrayDataProvider($records,
array(
'sort' => array( //optional and sortring
'attributes' => array(
'id', 'title',),
),
}
//or you could use $records=array_merge($prov1->data , $prov2->data);
$provAll = new CArrayDataProvider($records,
array(
'sort' => array( //optional and sortring
'attributes' => array(
'id',
'title'
),
),
'pagination' => array('pageSize' => 10) //optional add a pagination
)
)
);
//render a view
$this->render('custom',array('provAll' => $provAll))
;
```[...]
```php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $provAll,
'columns' => array('id', 'title'),
)
));
```
Both of two CActiveDataProvider data will be displayed in CGridView