I have 2 separate models (for 2 separate tables) containing some similar properties, which I want to combine into one GridView. The models are unrelated.
Model 1:
+----+------+----------------+-----+
| id | name | email | age |
+----+------+----------------+-----+
| 1 | Bob | bob@bob.bob | 22 |
| 2 | Ross | ross@ross.ross | 24 |
+----+------+----------------+-----+
Model 2:
+----+-------+-----------------+----------+-----------+
| id | name | email | location | Interests |
+----+-------+-----------------+----------+-----------+
| 1 | Mr | mr@mr.mr | Middle | Computers |
| 2 | Robot | robot@robot.bot | Nowhere | Hacking |
+----+-------+-----------------+----------+-----------+
I want to export the following data to a CSV (using kartik/Grid/Gridview/ExportMenu
), which works similarly to a GridView:
+----+-------+-----------------+----------+-----+-----------+
| id | name | email | Location | Age | Interests |
+----+-------+-----------------+----------+-----+-----------+
| 1 | Mr | mr@mr.mr | Middle | | Computers |
| 2 | Robot | robot@robot.bot | Nowhere | | Hacking |
| 3 | Bob | bob@bob.bob | | 22 | |
| 4 | Ross | ross@ross.ross | | 24 | |
+----+-------+-----------------+----------+-----+-----------+
The export widget works the same as a CGridView. You supply a dataProvider
(could have pagination) and the exported CSV contains all rows.
Currently I'm using Search models to return 2 ActiveDataProviders, and then I combine them with ArrayDataProvider:
$searchModel = new RegisteredUserSearch([$argumentsArray1]);
$dataProvider1 = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider1->pagination = ['pageSize' => 12];
$collectedEmailSearchModel = new CollectedEmailSearch([$argumentsArray2]);
$dataProvider2 = $collectedEmailSearchModel->search(Yii::$app->request->queryParams);
$dataProvider2->pagination = ['pageSize' => 12];
$data = array_merge($dataProvider1->getModels(), $dataProvider2->getModels());
$dataProvider = new ArrayDataProvider([
'allModels' => $data,
'pagination'=>[
'pageSize'=> 0
]
]);
Using $dataProvider1
or $dataProvider2
as the GridView's dataProvider
works fine, but using the combined $dataProvider
results in exporting only 24 rows. I tried changing the pageSize
of the dataProviders to 0, but that doesn't appear to make a difference.