One Buttons instance for use in multiple tables

One Buttons instance for use in multiple tables

tangerinetangerine Posts: 3,365Questions: 39Answers: 395

I have this

    $.ajax({
        url: "...path/to/js/buttons_export.js",
        dataType: "script"
    });

which is included in several individual tables scripts.
"buttons_export.js" creates a Buttons instance:

    // "Data Export" buttons collection.
    new $.fn.dataTable.Buttons(oTable, {
        name: "buttons-export",
        buttons: [
            {
                extend: "collection",
....

I'm now finding that I need different exportOptions for some tables. Is there any way I could insert exportOptions dynamically, where necessary?

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,991Questions: 87Answers: 421
    edited October 2021 Answer ✓

    In your script "buttons_export.js" you could check for the existence of the respective page or the respective data table and add different exportOptions depending on the page or the data table upon creation - which means you don't need to add them later.

    I don't think adding them later is possible at all. I think in that case you will have to create a new button that extends a button previously created and add the required export options.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Hi @rf1234, thanks for your time.
    Eventually I remembered that I have global controller names.
    So a pretty long switch at the top of "buttons_export.js" to allocate var cols according to controller name; then

    exportOptions: {
                       columns: cols
                  },
    

    Works so far. I'll come back if I hit a bump in the road.
    Regards,
    tangerine

Sign In or Register to comment.