Revision #3 has been created by Nashi on Sep 2, 2014, 9:07:54 AM with the memo:
Code beautified
« previous (#2)
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);
}
}
//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',),
),
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