php - Yii2: Export columns order -
i export file (expecially xls) generated yii2-export mimic gridview exporting columns in order selected in gridview configuration popup menu.
i mean, lets have 2 columns , b. in gridview configuration menu (little wrench icon) set b comes first. dynagrid output looks following:
b title| title -------|--------- b data | data however export ignores setting , outputs first column (because defined first in columns array passed configuration):
a title | b title ---------|---------- data | b data in db, have table tbl_dynagrid should contain configuration of gridview. found corresponding record id gridview_. content of data column not changing reordering columns via gridview configuration.
is there way how load (preferably php itself, without js) order of columns , export xls file order in mind?
thank help.
update:
i found out, gridview connected different database. value of data column in table tbl_gridview changing expected after each customization.
this way, need way how translate hashes used in gridview customization menu column ids 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 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 want able export columns in order selected in gridview, not in order set in $columns array.
the data exported based on dataprovider. based on should select column in .. sequence need ..
you should build dataprovider based on select assign each column in sequence need ..
$yourdataprovider = yourmodel::find() ->select('col1, col2, col3 ... ') ->where( ... ) ....
Comments
Post a Comment