Export

The built-in export function of model-grid only implements the export of simple csv format files. If you encounter file coding problems or can not meet your own needs, you can follow the steps below to customize the export function.

Laravel-Excel v3.*

Export support for the Laravel-Excel 3.* First install Laravel-Excel according to the documentation.

Then create an export class:

<?php

Namespace App\Admin\Extensions;

Use Ezadev\Admin\Grid\Exporters\ExcelExporter;

class PostsExporter extends ExcelExporter
{
    protected $fileName = 'Article list.xlsx';

    protected $columns = [
        'id' => 'ID',
        'title' => 'title',
        'content' => 'content',
    ];
}

Then use this export class in the Grid:

With the $columns setting above, only three specified three fields will be exported when exporting. If you want to export all the fields, specify the name of each field in order.

Laravel-Excel v2.*

This example uses Laravel-Excel as an excel library, and of course you can use any other excel library.

First install it:

And then create a new custom export class, such as app/Admin/Extensions/ExcelExpoter.php:

And then use this class in model-grid:

For more information on how to use Laravel-Excel, refer to laravel-excel/docs

Last updated