kartik-v / yii2-export

A library to export server/db data in various formats (e.g. excel, html, pdf, csv etc.)
http://demos.krajee.com/export
Other
165 stars 126 forks source link

ArrayDataProvider #244

Closed Andrewkha closed 6 years ago

Andrewkha commented 6 years ago

Does it work with ArrayDataProvider? In my case it still exports the current page data only

kartik-v commented 6 years ago

Share an example of your code to understand your config

Andrewkha commented 6 years ago

it's very basic, sorry, not sure how to make it code friendly...

`<?= \kartik\export\ExportMenu::widget([ 'dataProvider' => $employees, 'fontAwesome' => true, 'columns' => $columns, 'dropdownOptions' => [ 'label' => 'Export All', 'class' => 'btn btn-default' ] ]);?>


    <?= GridView::widget([
        'dataProvider' => $employees,
        'striped' => true,
        'hover' => true,
        'export' => false,
        'toolbar' => [
            '{toggleData}'
        ],
        'panel'=>[
            'type'=>GridView::TYPE_PRIMARY,
        ],
        'columns' => $columns
    ]);?>`
ThreepE0 commented 6 years ago

Just disable pagination before filtering. You can re-enable before viewing if you want. Let me know if you want an example

On Feb 15, 2018, at 3:15 AM, Andrewkha notifications@github.com wrote:

Does it work with ArrayDataProvider? In my case it still exports the current page data only

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kartik-v/yii2-export/issues/244, or mute the thread https://github.com/notifications/unsubscribe-auth/ADzhQP7R2OEJx11GAq_C5lqmZffJHhbSks5tU-e5gaJpZM4SGeMt .

Andrewkha commented 6 years ago

If I disable pagination, I would not need yii2-export. I will be able to export the data with GridView export capabilities. I started looking at this library exactly for the reason I need to export all the data but having pagination as well. There's such scenario in the examples for this library but it doesn't work in my case for some reason. I'm just wondering if this functionality supposed to work with ArrayDataProvider...

ThreepE0 commented 6 years ago

You missed my point; Disable pagination on the controller for filtering only, then re-enable before you display. Its the only way to allow filtering to apply to all items in the array. You still have pagination, just need to disable it before you run your filter function. If you need an example, let me know

On Feb 19, 2018, at 2:30 AM, Andrewkha notifications@github.com wrote:

If I disable pagination, I would not need yii2-export. I will be able to export the data with GridView export capabilities. I started looking at this library exactly for the reason I need to export all the data but having pagination as well. There's such scenario in the examples for this library but it doesn't work in my case for some reason. I'm just wondering if this functionality supposed to work with ArrayDataProvider...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kartik-v/yii2-export/issues/244#issuecomment-366608220, or mute the thread https://github.com/notifications/unsubscribe-auth/ADzhQPU-eV6MfY_h7FPOANiOwuN-934qks5tWSMWgaJpZM4SGeMt .

ThreepE0 commented 6 years ago

Sorry, I was incorrect in my recommendation; If you disable pagination only when the controller sees the POST attribute associated with the export function, you should be all set. I have this in my controller after the arraydataprovider is created but before render:

if(isset($_POST['export_type'])){$dataProvider->pagination = false;}

marthy123mm commented 6 years ago

Thanks so much @OceansCrashing , that is just im looking for!

Stern87 commented 5 years ago

Actually, the problem is that export is not working well with ArrayDataProvider because generateBody function is not using $models = array_values($this->_provider->getModels()); inside while loop, only before it. Instead, it's just $models = $this->_provider->getModels(); The Yii's ArrayDataProvider is returning getModels with keeping the keys because of setting "true" of preserve_keys parameter of array_slice function. By that, with pagination enabled you will always receive "Undefined offset" starting from the 2nd page.

ThreepE0 commented 5 years ago

Stern87: no. That’s not the problem described, and I’ve never had an issue with exporting just the current page. If you have that specific issue, open another issue. Seems like something else may be going on with your code though, as I haven’t experienced that issue.

The OP wanted to export all models and disable pagination, which I helped him with. Don’t necro an old issue with something unrelated.

Stern87 commented 5 years ago

If you read it carefully, you will see that this is a same issue. Nevertheless, I'm wondering what's the reason getting models in different way within one function?

ThreepE0 commented 5 years ago

This is not the same issue. If it is, stop being lazy and clarify. I did read, and I don’t see it; the original issue was that only current page was exported. This is exactly as you’d expect because that’s how pagination works. The fix was simple (disable pagination upon exporting.) Again, this is by design and as expected behavior. If you have a question about the generateBody function, open a new issue as it’s not related at all to this issue and pagination.

naduvko commented 2 years ago

It is the same issue, because with ActiveDataProvider export get all the models, despite the pagination. With ArrayDataProvider it exports only first page.