Quantcast
Channel: DataTables 1.10 — DataTables forums
Viewing all articles
Browse latest Browse all 2364

Triggering export after table is redrawn to show all records

$
0
0

Hello all,
I have datatables set up to use server side processing and as we all know, if you click export it will only export what it has in memory. This makes perfect sense, however I need the ability to export all rows. I know there are various other questions about this, and other ways to solve it, however I am interested in try to automatically change the page length to 'All' when the user clicks the export button.

i.e.:

 "buttons": 
            [
                { 
                    extend: "edit",   
                    editor: editor 
                },
                { 
                    extend: 'excel',
                    text: 'Export to Excel',
                    action: function ( e, dt, node, config ) {
                        theTable.page.len(-1).draw();
                        theTable.button('1').trigger();
                        
                    }
                }
            ]

The above throws a Stackoverflow (which I think makes some sense as it looks like an endless loop). Long story short how do I (or can I?) change the action of the excel export to first change the page length to 'All' then export the data? I can always instruct my users to manually select 'All' then export, but they won't listen.

I have also tried:

 "buttons": 
            [
                { 
                    extend: "edit",   
                    editor: editor 
                },
                { 
                    extend: 'excel',
                    text: 'Export to Excel',
                    action: function ( e, dt, node, config ) {
                        theTable.page.len(-1).draw();
                        $.fn.dataTable.ext.buttons.excelHtml5.action.call(this, e, dt, node, config);
                        
                    }
                }
            ]

Which 'works' in that it does export the data but it doesn't wait for the draw to complete which means it only exports the first page. Is there anyway to have the $.fn.dataTable.ext.buttons.excelHtml5.action.call(this, e, dt, node, config); wait until after the draw completes?

Thoughts?


Viewing all articles
Browse latest Browse all 2364

Trending Articles