Demonstration examples for the yii2-export extension. All the examples below need a dataProvider
which can be passed like any data provider to a \kartik\grid\GridView.
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)
kartik\grid\GridView
. Set a label for your export menu dropdown.false
or null
within ExportMenu::exportConfig
. In addition, this example also shows how you can configure specific properties for a format. For example, you can control PDF output rendering by setting the pdfConfig
setting. The pdfConfig
setting within ExportMenu::exportConfig
array for the format ExportMenu::FORMAT_PDF
, will allow you to configure the settings for the kartik\mpdf\Pdf
component.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.cellFormat
within the column's headerOptions
, contentOptions
, or footerOptions
. You can also set cellFormat
for each cell configured within ExportMenu::contentBefore
and ExportMenu::contentAfter
. The value for cellFormat
must be one of the PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_
constants. This setting will override any other autoFormat
setting.hiddenColumns
(e.g. let's hide the SerialColumn and the ActionColumn). Note that hiddenColumns
only control the display of columns in the column selector. Hidden columns will be displayed in the export if they are a part of selectedColumns
. We can also disable certain columns in the column selector by setting disabledColumns
(e.g. let's disable ID and Author Name). Similar to hiddenColumns
, disabled columns will be displayed in the export if they are a part of selectedColumns
.hiddenColumns
as well (though hidden from selection, this will still be displayed on export as it is set in selectedColumns
). Set noExportColumns
to hide from export and the dropdown (e.g. let's not export the Status column). In addition customize the column labels displayed in the column selector (e.g. change Buy Amount and Sell Amount labels).ExportMenu::TARGET_BLANK
. Display export menu dropdown embedded within the toolbar of kartik\grid\GridView as a separate menu. Uses the plugin ability of kartik\grid\GridView. Note, in the example below, the Full Menu from yii2-export is generated along with the inbuilt Page Menu from yii2-grid. In addition, this example includes a pjax enabled grid. You need to set ExportMenu::pjaxContainerId
and GridView::pjaxSettings['options']['id']
to the same value.asDropdown
to false in this case. Hence the Columns Selector will not be displayed (you will need to render the exportColumnsView
on your own if needed).asDropdown
to false in this case. Hence the Columns Selector will not be displayed (you will need to render the exportColumnsView
on your own if needed).options['id']
for each export menu. By default this will be uniquely generated by the yii2-export extension anyway.stream
property to false
. This way the exported data will be directly written to a file instead of streaming to buffer. The exported file will be then displayed as a web accessible link for download. You may see some improvement by avoiding memory issues due to output buffering, and the file is saved directly to a web server folder. You can provide the folder
and linkPath
properties to set the folder for saving and the web accessible link location for the saved file respectively. The extension will automatically show a link to the saved file based on above settings. You can set the afterSaveView
file to point to your own view that displays the generated file link. Note: The target
property will automatically be overridden to ExportMenu::TARGET_SELF
or _self
when this is set.linkPath
and move internally the generated file from the temporary folder
to your target link location. You can use and setup the onGenerateFile
Closure callback to manage this movement. It also configures the deleteAfterSave
property to true
to automatically delete the saved files on the server folder
after its been linked via the linkPath
.batchSize
property to fetch models in batches of this size from the dataProvider
. This will improve the memory usage by not loading all the models into memory. The exported output will still be a single file containing all data, but it will be rendered with models selected in a batch mode to generate output rows. Each batch will read batchSize
number of models at a time, and once processed the next batch of models will be retrieved from the dataProvider
.
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.