Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

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

Closed
angelinchaustipy opened this issue Jun 19, 2021 · 3 comments

Comments

@angelinchaustipy
Copy link

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

@wattsie
Copy link

wattsie commented Jun 30, 2021

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
Copy link

mUcHG0Di commented Jul 7, 2021

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 :')

@pascalbaljet
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants