I tried to find, without success, how to export a filtered grid in Yii2 without using a plugin. All I find is examples with Kartik’s export widget. I have no problem exporting the result of a query in phpexcel but I don’t understand how to deal with a dataprovider. Ideally, I want to take an array of all the data in a filtered grid, not just a page and loop through it to get my data into phpexcel or simpoly export it to csv. So let’s say I have a simple product model with a search model and I want to dislay just the ‘id’ in a view. And let’s say I have a filterd grid with 100 products. In my view, I’d have something like:
foreach ($dataprovider->models as products) {
echo products->id;
}
And in my controller, my dataprovider would get the search results (like the default index controller created by gii for a grid). All I can get is the fist 10 products (this is the default page size). I just need a tip to put me on track on how to achieve this, as I looked at the doc for Activedataprovider, but could’nt find the answer there.
For the rest, it works exactly like stated in Phpexcel documentation. And you have a lot more options for formating your Excel file that you would have with an extension like Kartik’S one (even though it’s a great extension).