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

Export grouped data - no sum for last group, and no cell merge #306

Closed davidovv closed 4 years ago

davidovv commented 4 years ago

I believe there is a bug exporting grouped grid view. I used grid view, defined grouping on first two columns, and (only for second column), and merged grouped cells and the grid view works fine, everything is like it is supposed to be. I used same columns for ExportMenu, and the result is that last group (on second level) doesn't show sum and the rows are all separated (no merged cells) Sample export file is in attachment, sample is xlsx but the same but is there for pdf export. kartik-export.xlsx

kartik-v commented 4 years ago

Grouping only works with yii2-grid not with yii2-export.

The yii2-grid inbuilt page export will allow you to export grouped data via javascript rendering. Yii2 export uses a different server library PhpSpreadsheet to export data. You may need to use PhpSpreadsheet features to group your data.

davidovv commented 4 years ago

I am confused with this response 'Grouping only works with yii2-grid not with yii2-export.' The attached sample was generated By yii2-export and i understand that that file was generated with phpspreadsheet. The export shows groups and sums so i guess yii2-export supports grouping. Please check the kartik-export.xlsx file, you can see the groups and sums and merged cells inside. The thing is (the bug) that for the last group there is no sum and cells are not merged.

kartik-v commented 4 years ago

Share your configuration to understand and reproduce

davidovv commented 4 years ago

Here is how i configured columns $gridColumns = [ //['class' => 'yii\grid\SerialColumn'], [ 'attribute' => 'group_id', 'format' => 'raw', 'value' => function ($data) { if (isset($data->group)) return $data->group->name; return null; }, 'group' => true, // enable grouping 'groupedRow' => true, 'groupFooter' => function ($model, $key, $index, $widget) { // Closure method return [ 'content' => [// content to show in each summary cell 2 => 'Ukupno (' . $model->subject->name . ')', 6 => GridView::F_SUM, ], 'contentFormats' => [// content reformatting for each summary cell 6 => ['format' => 'number', 'decimals' => 2], ], 'contentOptions' => [// content html attributes for each summary cell 2 => ['style' => 'font-variant:small-caps'], 6 => ['style' => 'text-align:right'], ], // html attributes for group summary row 'options' => ['class' => 'info table-info', 'style' => 'font-weight:bold;'] ]; }, // move grouped column to a single grouped row ], [ 'attribute' => 'subject_id', 'format' => 'raw', 'value' => function ($data) { if (isset($data->subject)) return $data->subject->name; return null; }, 'group' => true, // enable grouping 'groupedRow' => true, 'pageSummary' => true, 'groupFooter' => function ($model, $key, $index, $widget) { // Closure method return [ 'content' => [// content to show in each summary cell 1 => 'Ukupno (' . $model->subject->name . ')', 6 => GridView::F_SUM, ], 'contentFormats' => [// content reformatting for each summary cell 6 => ['format' => 'number', 'decimals' => 2], ], 'contentOptions' => [// content html attributes for each summary cell 1 => ['style' => 'font-variant:small-caps'], 6 => ['style' => 'text-align:right'], ], // html attributes for group summary row 'options' => ['class' => 'info table-info', 'style' => 'font-weight:bold;'] ]; }, ], [ 'attribute' => 'access_time', 'format' => 'raw', 'value' => function ($data) { return ($data->access_time); }, ], [ 'attribute' => 'duration', 'headerOptions' => ['style' => 'width:5%; text-align:right'], 'format' => 'raw', 'value' => function ($data) { return number_format(round($data->duration / 3600, 3), 3); }, ], [ 'attribute' => 'approved', 'format' => 'raw', 'value' => function ($data) { return null; }, ], ];

and here is how i created ExportMenu

ExportMenu::widget([ 'dataProvider' => $dataProvider, 'columns' => $gridColumns, 'exportConfig' => [ ExportMenu::FORMAT_TEXT => false, ExportMenu::FORMAT_HTML => false, ExportMenu::FORMAT_EXCEL => false, ], //'fontAwesome' => true, //'batchSize' => 20, 'showConfirmAlert' => false, 'enableFormatter' => false, 'filename' => 'access', 'target' => ExportMenu::TARGET_BLANK, 'dropdownOptions' => [ 'label' => 'Export', ] ]);

davidovv commented 4 years ago

Sorry i couldn't format this code here, i pasted text in 'insert code' tag but it still isn't formatted. i can attach it in file if you need.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.