Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excel export #42

Open
asbator opened this issue Dec 8, 2021 · 4 comments
Open

Excel export #42

asbator opened this issue Dec 8, 2021 · 4 comments

Comments

@asbator
Copy link

asbator commented Dec 8, 2021

How do Excel/export boilerplate work?
I can see generator adds this to controllers:

use App\Exports\ClassNameExport; 
use Maatwebsite\Excel\Excel //<-- no semicolon

But except that cant find out how data export works?

@coolsam726
Copy link
Owner

Hi @asbator, Unfortunately I didn't get time to implement excel imports and exports in the code generators. What you see is just a dummy placeholder because I am planning to implement them as soon as I get time. For now you can spin up your own implementation. Sorry about that. I will leave this issue open in order to keep track of the implementation plan.

@asbator
Copy link
Author

asbator commented Dec 9, 2021

Did you have any plan? Which tools and how to use them?

@coolsam726
Copy link
Owner

Yea. The plan was to use https://laravel-excel.com/

@asbator
Copy link
Author

asbator commented May 26, 2022

I've ended up just using build into DataTables Excel export button.

Server side processing jquery datatble doesn't support all data to be exported.
This function makes the datatable to export all records when "server side processing" is on.
Todo: prevent user from clicking and re-running export while process is not finished (causes returning one page result).

/* paste inside $(document).ready(), probably new CDN links are needed inside app.blade.php */

buttons: [
     { extend: 'excel', action: newexportaction, "titleAttr": 'Export'}, 
],

/* paste after (outside) vue.js export default in DtComponent.vue */

function newexportaction(e, dt, button, config) {
    var self = this;
    var oldStart = dt.settings()[0]._iDisplayStart;
    dt.one('preXhr', function (e, s, data) {
        // Just this once, load all data from the server...
        data.start = 0;
        data.length = 2147483647;
        dt.one('preDraw', function (e, settings) {
            // Call the original action function
            if (button[0].className.indexOf('buttons-copy') >= 0) {
                $.fn.dataTable.ext.buttons.copyHtml5.action.call(self, e, dt, button, config);
            } else if (button[0].className.indexOf('buttons-excel') >= 0) {
                $.fn.dataTable.ext.buttons.excelHtml5.available(dt, config) ?
                    $.fn.dataTable.ext.buttons.excelHtml5.action.call(self, e, dt, button, config) :
                    $.fn.dataTable.ext.buttons.excelFlash.action.call(self, e, dt, button, config);
            } else if (button[0].className.indexOf('buttons-csv') >= 0) {
                $.fn.dataTable.ext.buttons.csvHtml5.available(dt, config) ?
                    $.fn.dataTable.ext.buttons.csvHtml5.action.call(self, e, dt, button, config) :
                    $.fn.dataTable.ext.buttons.csvFlash.action.call(self, e, dt, button, config);
            } else if (button[0].className.indexOf('buttons-pdf') >= 0) {
                $.fn.dataTable.ext.buttons.pdfHtml5.available(dt, config) ?
                    $.fn.dataTable.ext.buttons.pdfHtml5.action.call(self, e, dt, button, config) :
                    $.fn.dataTable.ext.buttons.pdfFlash.action.call(self, e, dt, button, config);
            } else if (button[0].className.indexOf('buttons-print') >= 0) {
                $.fn.dataTable.ext.buttons.print.action(e, dt, button, config);
            }
            dt.one('preXhr', function (e, s, data) {
                // DataTables thinks the first item displayed is index 0, but we're not drawing that.
                // Set the property to what it was before exporting.
                settings._iDisplayStart = oldStart;
                data.start = oldStart;
            });
            // Reload the grid with the original page. Otherwise, API functions like table.cell(this) don't work properly.
            setTimeout(dt.ajax.reload, 0);
            // Prevent rendering of the full data to the DOM
            return false;
        });
    });
    // Requery the server with the new one-time export settings
    dt.ajax.reload();
};

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

No branches or pull requests

2 participants