How to add an action to the API?

How to add an action to the API?

lenamtllenamtl Posts: 265Questions: 65Answers: 1
edited November 2017 in Free community support

I'm looking to add this hack to my code
This can be a temporary fix for colvis, responsive export when using visible selector.
I'm referring to this post https://github.com/DataTables/Responsive/issues/90

buttons: [
    {
        name: 'print',
        extend: 'print',
        exportOptions: {
           columns: [':visible:not(.not-export-col):not(.hidden)'],
        },
        action: function(e, dt, button, config) {
            responsiveToggle(dt);
            $.fn.DataTable.ext.buttons.print.action(e, dt, button, config);
            responsiveToggle(dt);
        }
    },
]

I just don't know where to put the toggle action toggle code
I believe that need to be on datatables,js but not sure where and what is the syntax I should use.

responsiveToggle(dt) {
    $(dt.table().header()).find('th').toggleClass('all');
    dt.responsive.rebuild();
    dt.responsive.recalc();
}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin
    Answer ✓

    You should be able to put that function just about anywhere. As long as it can be called from the action method, then its find. You could make it a global function for example.

    Allan

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1

    Ok I finally put the code in datatables.js
    otherwise I was getting errors.

    function responsiveToggle(dt) {
       $(dt.table().header()).find('th').toggleClass('all');
       dt.responsive.rebuild();
       dt.responsive.recalc();
    }
    

    This is working ok for now, thanks

This discussion has been closed.