Yii 2 Export Menu

Latest Stable Version Latest Unstable Version Total Downloads Monthly Downloads Daily Downloads
Thankful to Krajee!
to get more out of us.

NOTE: This extension depends on the kartik-v/yii2-krajee-base extension which in turn depends on the yiisoft/yii2-bootstrap extension. Check the composer.json for this extension's requirements and dependencies that may be updated by composer.

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.

Display only the export menu dropdown, without any grid. Note that the column selector is displayed along with the grid by default.

Click for demo

Display export menu dropdown along with a basic kartik\grid\GridView. Set a label for your export menu dropdown.

Click for demo

Customize your column selector with a custom label. You can choose to hide certain columns from the column selector by 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.

Click for demo

Extension of column selector case 1 to preset your column selections on load (let's say only ID, Name, Author Name, Color, & Publish Date is preselected). Let's add one more column (Color) to the 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).

Click for demo

Set target for export form submission to 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.

Click for demo

Variation of advanced case 1. Display export menu dropdown merged along with the dropdown items of the default kartik\grid\GridView export menu. Uses the plugin ability of kartik\grid\GridView. Display your own customized menu list and style it with CSS. Note you will set 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).

Click for demo

Display your own customized menu list and style it with CSS. Note you will set 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).

Click for demo

An example showing multiple export menu widgets on the same page with different data providers. It also shows an use of 2 array data providers. Note you must set unique identifiers options['id'] for each export menu. By default this will be uniquely generated by the yii2-export extension anyway.

Click for demo

An example showing how you can download larger export files without streaming to browser. You need to set 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.

Click for demo

A variation of large files linking scenario where you can control the 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.

Click for demo

Scenario for batch loading of models. You can set the 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.

Click for demo