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.
Use App\Admin\Extensions\PostsExporter;
$grid->exporter(new PostsExporter());
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.
And then create a new custom export class, such as app/Admin/Extensions/ExcelExpoter.php:
<?php
namespace App\Admin\Extensions;
use Ezadev\Admin\Grid\Exporters\AbstractExporter;
use Maatwebsite\Excel\Facades\Excel;
class ExcelExpoter extends AbstractExporter
{
public function export()
{
Excel::create('Filename', function($excel) {
$excel->sheet('Sheetname', function($sheet) {
// This logic get the columns that need to be exported from the table data
$rows = collect($this->getData())->map(function ($item) {
return array_only($item, ['id', 'title', 'content', 'rate', 'keywords']);
});
$sheet->rows($rows);
});
})->export('xls');
}
}
And then use this class in model-grid:
use App\Admin\Extensions\ExcelExpoter;
$grid->exporter(new ExcelExpoter());
For more information on how to use Laravel-Excel, refer to laravel-excel/docs