Custom Button: how to get list

Custom Button: how to get list

anakin59490anakin59490 Posts: 20Questions: 7Answers: 0

Hi,

i need to get list when i click on new button.
Important : i must keep the sort (when it's used) like 'csv' function

{
          text: 'Some button',
          className: 'red',
          action: function (e, dt, node, config) {
            // alert('Button activated');
            console.log(e);
            console.log(dt);
            console.log(node);
            console.log(config);
          }
 }

Thank you

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @anakin59490 ,

    A list of what?

    Cheers,

    Colin

  • anakin59490anakin59490 Posts: 20Questions: 7Answers: 0

    The table rows

  • anakin59490anakin59490 Posts: 20Questions: 7Answers: 0

    exactly the same as csv export function except i keep the list for another custom function

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi @anakin59490 ,

    rows().data() will give you all the data for all the rows. You can then format/manipulate/export it however you want in the button.

    Cheers,

    Colin

  • anakin59490anakin59490 Posts: 20Questions: 7Answers: 0

    Hi,

    Thank you colin !
    I also found another way with the following lines :

    action: function (e, dt, node, config) {
      console.log('Elément filtrés : ' + dt.buttons.exportData().body.length);
      dt.buttons.exportData().body.forEach((item) => {
         console.log(item);
      });
    }
    
This discussion has been closed.