Closed angelinchaustipy closed 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.
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:
Create an extension of InteractsWithQueryBuilder.vue, to remove the following condition in method getColumnsForQuery:
if (enabledColumns.length === Object.keys(columns || {}).length) {
return [];
}
Import your new InteractsWithQueryBuilder file in your view, instead of the original one:
import InteractsWithQueryBuilder from '@/InteractsWithQueryBuilder';
Create a button or something, that executes the following:
const query = this.queryBuilderString; // The query
const url = route('excel.export'); // Your export route
const model = 'App\Models\User'; // The model to export
window.location.href = `${url}?${query}&model=${model}`
- 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 :')
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.
I am needing to export the records that are filtered in the table in XLS or PDF Format using Laravel and VueJS.