Skip to content

Conversation

@yajra
Copy link
Owner

@yajra yajra commented Mar 18, 2021

This PR will improve support for the laravel-excel package export class.

  1. All rows will now be included instead of the filtered values displayed in the table. (Potential breaking change)
  2. Add DataTablesCollectionExport abstract class.

Example Usage

  1. Create an export class php artisan make:export UsersExport
  2. Update the generated export class and extend DataTablesCollectionExport
namespace App\Exports;

use Yajra\DataTables\Exports\DataTablesCollectionExport;

class UsersExport extends DataTablesCollectionExport
{
    
}
  1. Update your UsersDataTable class and set protected $exportClass = UsersExport::class
class UsersDataTable extends DataTable
{
    protected $exportClass = UsersExport::class;
  1. Update your export class as needed. See official package docs: https://docs.laravel-excel.com/3.1/exports/collection.html

Example Export Class

<?php

namespace App\Exports;

use Maatwebsite\Excel\Concerns\WithMapping;
use Yajra\DataTables\Exports\DataTablesCollectionExport;

class UsersExport extends DataTablesCollectionExport implements WithMapping
{
    public function headings(): array
    {
        return [
            'Name',
            'Email',
        ];
    }

    public function map($row): array
    {
        return [
            $row['name'],
            $row['email'],
        ];
    }
}

@yajra yajra merged commit d8b7109 into 4.0 Mar 18, 2021
@yajra yajra deleted the better-export branch March 18, 2021 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants