exportMenuStyle
and/or exportMenuHeaderStyle
properties available in kartik\grid\DataColumn
and kartik\grid\SerialColumn
can be configured as an array. This will be detected and applied by \PhpOffice\PhpSpreadsheet\Style\Style::applyFromArray()
for the cells. Note that with v1.2.9, the ExportMenu will intelligently also detect and auto format and style the columns based on the column hAlign
, vAlign
and format
properties to a limited extent. This example also shows how you can have different column configurations for the GridView and ExportMenu.Not seeing the updated content on this page! Hard refresh your browser to clean cache for this page (e.g. SHIFT-F5 on Windows Chrome)
use kartik\export\ExportMenu; use kartik\grid\GridView; echo ExportMenu::widget([ 'dataProvider' => $dataProvider, 'columns' => [ [ 'class' => 'kartik\grid\SerialColumn', 'exportMenuStyle' => [ // format the serial column cells 'fill' => [ 'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'color' => ['argb' => 'FFE5E5E5'] ] ] ], ['attribute' => 'id', 'hAlign' => GridView::ALIGN_CENTER], 'name', [ 'attribute'=>'author_id', // note this column config is changed in ExportMenu vs GridView 'label'=>'Author', 'value'=>function ($model, $key, $index, $widget) { return $model->author->name; } ], [ 'attribute'=>'color', 'width'=>'100px', 'exportMenuStyle' => function($model, $key, $index, $column) { // as a Closure function $colors = [ 'blue' => 'FF0000FF', 'black' => 'FF000000', 'brown' => 'FFA52A2A', 'cyan' => 'FF00FFFF', 'red' => 'FFFF0000', 'green' => 'FF008000', 'orange' => 'FFFFA500', 'pink' => 'FFFFC0CB', 'yellow' => 'FFFFFF00', ]; return ['font'=>['bold'=>true, 'color'=>['argb' => $colors[$model->color]]]]; } ], [ 'attribute'=>'publish_date', 'exportMenuStyle' => ['numberFormat' => ['formatCode' => 'YYYY-MM-DD']] // formats a date ], [ 'attribute'=>'status', // note this column config is changed in ExportMenu vs GridView ], // next 2 columns will be auto-formatted based on decimal format set ['attribute'=>'buy_amount','format'=>['decimal',2], 'hAlign'=>'right', 'width'=>'110px'], ['attribute'=>'sell_amount','format'=>['decimal',2], 'hAlign'=>'right', 'width'=>'110px'], // skip rendering the Action Column in export menu // ['class' => 'kartik\grid\ActionColumn', 'urlCreator'=>function(){return '#';}] ], 'dropdownOptions' => [ 'label' => 'Export All', 'class' => 'btn btn-outline-secondary btn-default' ] ]) . "<hr>\n". GridView::widget([ 'dataProvider' => $dataProvider, 'columns' => $gridColumns ]);
$gridColumns = [ ['class' => 'kartik\grid\SerialColumn'], 'id', 'name', [ 'attribute'=>'author_id', 'label'=>'Author', 'vAlign'=>'middle', 'width'=>'190px', 'value'=>function ($model, $key, $index, $widget) { return Html::a($model->author->name, '#', []); }, 'format'=>'raw' ], 'color', 'publish_date', 'status', ['attribute'=>'buy_amount','format'=>['decimal',2], 'hAlign'=>'right', 'width'=>'110px'], ['attribute'=>'sell_amount','format'=>['decimal',2], 'hAlign'=>'right', 'width'=>'110px'], ['class' => 'kartik\grid\ActionColumn', 'urlCreator'=>function(){return '#';}] ];
Comments & Discussion
Note
You can now visit the Krajee Webtips Q & A forum for searching OR asking questions OR helping programmers with answers on these extensions and plugins. For asking a question click here. Select the appropriate question category (i.e. Krajee Plugins) and choose this current page plugin in the question related to field.
The comments and discussion section below are intended for generic discussions or feedback for this plugin. Developers may not be able to search or lookup here specific questions or tips on usage for this plugin.