Skip to content

Conversation

@yajra
Copy link
Owner

@yajra yajra commented Mar 18, 2021

Add fast export function support for https://github.com/rap2hpoutre/fast-excel package.

@yajra
Copy link
Owner Author

yajra commented Mar 19, 2021

Usage

  1. Install fast-excel using composer require rap2hpoutre/fast-excel.
  2. Create a dataTable class php artisan datatables:make Users
  3. Adjust UsersDataTable as needed.
  4. Set property $fastExcel = true.
class UsersDataTable extends DataTable
{
    protected $fastExcel = true;

    ...
}
  1. DataTables will now export csv & excel using fast-excel package.

Faster export by disabling the fast-excel callback

  1. Just set property $fastExcelCallback = false. This is enabled by default for a better formatted output of exported file.
class UsersDataTable extends DataTable
{
    protected $fastExcel = true;
    protected $fastExcelCallback = false;
  1. Exported file will now be based on how your query was structured. No header formatting and all selected columns in sql will be included in the output.

@yajra yajra changed the title [WIP] Add support for fast-excel for exporting with xls and csv. [4.x] Add support for fast-excel for exporting with xls and csv. Mar 19, 2021
@yajra
Copy link
Owner Author

yajra commented Mar 19, 2021

Using custom callback

Just override the fastExcelCallback method:

class UsersDataTable extends DataTable
{
    protected $fastExcel = true;

    public function fastExcelCallback()
    {
        return function ($row) {
            return [
                'Name' => $row['name'],
                'Email' => $row['email'],
            ];
        };
    }

...

@yajra yajra changed the title [4.x] Add support for fast-excel for exporting with xls and csv. [4.x] Add support for fast-excel when exporting to excel and csv. Mar 19, 2021
@yajra yajra merged commit bc9a145 into 4.0 Mar 19, 2021
@yajra yajra deleted the fast-excel-export branch March 19, 2021 08:59
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