Difference between #1 and #3 of
multiple CActiveDataProviders in one CGridView

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
4 1
9 followers
Viewed: 33 056 times
Version: 1.1
Category: How-tos
Last updated by: Nashi
Created on: Jun 24, 2013
Last updated: 10 years ago
Update Article

Revisions

View all history