robsontenorio/vue-api-query

Exporting data as Excel

Opened this issue · 3 comments

Hi,

i would use the same query builder syntax to export data as Excel.

For example, calling:

User.
    .where(toRaw(filters.value))
    .orderBy((descending ? '-' : '') + sortBy)
    .export('users.xlsx');

would call /users/export with the same querystring parameters of get() method and then use a snippet similar to

axios.get(url, { responseType: 'blob' })
      .then(response => {
        const blob = new Blob([response.data], { type: 'application/pdf' })
        const link = document.createElement('a')
        link.href = URL.createObjectURL(blob)
        link.download = label
        link.click()
        URL.revokeObjectURL(link.href)

or https://www.npmjs.com/package/file-saver

I'm using https://docs.laravel-excel.com/3.1/exports/ and would be incredibly helpful replicate the same get() behaviour exporting the Excel from

public function export()
    {
        $data = QueryBuilder::for(User::class)
            ->allowedFilters(['soggetto', 'soggetto.nominativo', 'login', 'tipo_utente', 'roles.id'])
            ->allowedIncludes(['soggetto'])
            ->with('soggetto')
            ->get();

        return Excel::download(new UsersExport($data), 'users.xlsx');
    }

Maybe is already possible with some hack :)

Thanks

I've opened the PR #266 with the new file() method handling a Blob

Any updates on this?

i've forked and internalized the code of this package in my project because i think it's dead as the maintainer is not replying to any issues since a while