Git Product home page Git Product logo

Comments (3)

wattsie avatar wattsie commented on June 30, 2024

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.

from inertiajs-tables-laravel-query-builder.

mUcHG0Di avatar mUcHG0Di commented on June 30, 2024

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

from inertiajs-tables-laravel-query-builder.

pascalbaljet avatar pascalbaljet commented on June 30, 2024

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.

from inertiajs-tables-laravel-query-builder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.