I would like the export file (expecially XLS) generated by Yii2-export to mimic gridview by exporting all columns in order selected in gridview configuration popup menu.
I mean, lets have two columns A and B. In gridview configuration menu (Little wrench icon) I set that B comes first. My dynagrid output looks like following:
B title| A title
-------|---------
B data | A data
However the export completely ignores this setting and outputs A as first column (because it is defined first in columns array passed as configuration):
A title | B title
---------|----------
A data | B data
In DB, I have table tbl_dynagrid which should contain configuration of gridview. I found corresponding record with id gridview_. But the content of data column is not changing with reordering columns via gridview configuration.
Is there way how to load (preferably by PHP itself, without JS) order of columns and export to XLS file with that order in mind?
Thank you for help.
Update:
I found out, that gridview is connected to different database. Value of data column in table tbl_gridview is changing as expected after each customization.
This way, I need a way how to translate hashes used in gridview customization menu as column IDs to actual column names or so.
Actual code:
$dataProvider = //..
$pageName = //..
Columns array:
$columns = [
[ 'attribute' => 'col1', 'encodeLabel' => false, 'label' => 'Column A' ],
[ 'attribute' => 'col2', 'encodeLabel' => false, 'label' => 'Column B' ]
];
Export widget:
echo ExportMenu::widget([
'dataProvider' => $dataProvider,
'target'=>ExportMenu::TARGET_SELF,
'showConfirmAlert'=>false,
'container'=>['class'=>'myclass'],
'filename'=>'test',
'columns' => $columns,
'fontAwesome' => true,
'dropdownOptions' => [
'label' => Yii::t('layout','Export'),
'class' => 'btn btn-default'
]]);
And finally dynagrid:
$dynagrid = DynaGrid::begin([
'columns'=>$columns,
'theme'=>'simple-striped',
'showPersonalize'=>true,
'allowThemeSetting'=>false,
'allowFilterSetting'=>false,
'allowSortSetting'=>false,
'toggleButtonGrid'=>['class'=>'toggleButton'],
'gridOptions'=>[
'dataProvider'=>$dataProvider,
'options'=>['class'=>'myid'],
'filterModel'=>$searchModel,
'showPageSummary'=>false,
'floatHeader'=>false,
'pjax'=>false,
'toolbar' => [
['content'=>'{dynagridFilter}{dynagridSort}{dynagrid}'],
'{export}',
]
],
'options'=>['id'=>$pageName]
]);
All I want is to be able to export columns in order selected in gridview, not in the order they are set in $columns array.