protonemedia / inertiajs-tables-laravel-query-builder

Inertia.js Tables for Laravel Query Builder
https://protone.media/en/blog/introducing-inertiajs-tables-a-datatables-like-package-for-laravel-query-builder
MIT License
438 stars 129 forks source link

Is there any way to grab the filtered values and export them to PDF or XLS? #29

Closed angelinchaustipy closed 3 years ago

angelinchaustipy commented 3 years ago

I am needing to export the records that are filtered in the table in XLS or PDF Format using Laravel and VueJS.

wattsie commented 3 years ago

This would be awesome. At a minimum CSV would be good (ie JsonCSV).

I do see a possible issue when exporting large amount of data. Inertia seems to imposed a 640k limit (at least on firefox) as I keep getting NS_ERROR_ILLEGAL_VALUE when trying to access large datasets.

I expect, it may require a second controller, via an api style call (ie not rendered by Inertia) to pass all the data (axios etc).

Would be nice to pass the current filters and column status props so you can match what is being displayed.

Cheers.

mUcHG0Di commented 3 years ago

I made a controller for this, using FastExcel for export. https://gist.github.com/mUcHG0Di/9d133aec56cfe98d3296bca0c64aad74

Instructions are commented in the gist, but in a few words:


- Add the route: 
`Route::get('excel/export', \App\Http\Controllers\ExcelController::class)->name('excel.export');`

Obs.: Relation columns should be with dot notation, and you need to create the Sort class in app/Sorts/{MainModel}/{RelationModel} with Sort suffix, ie: app/Sorts/Product/OwnerSort.php (to support sorting)

Example:
    return Inertia::render('Users/Index', [
        'users' => $users,
    ])->table(function (InertiaTable $table) {
        $table->addColumns([
            'email' => 'Email address',
            'category.name' => 'Category',
            'latestHistory.status.name' => 'Status',
        ]);
    });


And it should work with no modifications.. In most cases :')
pascalbaljet commented 3 years ago

PDF/XLS exports are out of scope for this package, but I suggest looking at Laravel Excel. Maybe you could use the Collection Export feature.