Dynamatically update the page range during export

Dynamatically update the page range during export

dagldnxlnddagldnxlnd Posts: 1Questions: 1Answers: 0

I would like to allow users to change the page range (current page, all pages, selected) they would like to export the table.
I've tried the exportOptions, but seems variables in the exportOptions don't work.

Is there any way to achieve this?

Below is the code I use:

var page_range = 'current';

{
                                extend: 'csvHtml5',
                                //added for ipad export
                                charset: 'utf-8',
                                bom: true,
                                extend: 'csv',
                                //end of ipad
                                exportOptions: {
                                    modifier: {
                                        // DataTables core
                                        order: 'index', // 'current', 'applied',
                                        //'index', 'original'
                                        page: page_range, // 'all', 'current'
                                        search: 'applied' // 'none', 'applied', 'removed'
                                    },
                                    columns: ':visible:not(:first-child)'
                                }
                            },

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Having an official UI to control that sort of thing is something that I plan to add to DataTables later in the year. Until then, what you have should work, but it would always be current, even if you changed what page_range is, since that is the value of the variable when the table is initialised. Is that the problem you are running into? You were expecting it to update to match whatever page_range is later changed to?

    There isn't really a good way to handle that yet I'm afraid. Perhaps exportOptions should be made to accept a function which would return an object of that structure, which would resolve this (assuming I've understood the issue correctly).

    Allan

Sign In or Register to comment.