Toggle selected rows with a button

Toggle selected rows with a button

parismiguelparismiguel Posts: 7Questions: 3Answers: 0

Hi!

I'm trying to toggle only selected rows within a table using a button but, so far, all I've got is to filter only those in the current page within a collection of pages. Could you please help me what to do?

  {
                 text: '<i class="fa fa-list" style="color:orange;"></i>',
                 action: function (e, dt, node, config) {
                     //This works only in current page
                     $('#tblUsers tbody tr').not('.selected').toggle();
                     //This doesn't work at all
                     tableUsers.rows({ selected: true }).data().draw();
                 },
                 className: 'vcaBtnTable'
             },

Answers

  • parismiguelparismiguel Posts: 7Questions: 3Answers: 0

    OK... after hours of try and error, I've came with this solution that works ebautifully to my purposes.

      if (tableActions.rows({ selected: false }).count() == 0) {
                              dt.ajax.reload(function () {
                                  dt.rows('.selected').select();
                              });
                          }
                          else {
                              $("#tblActions").DataTable().rows({ selected: false }).remove().draw();
                          }
    

    Bear in mind that I had initialized my table as follows:

    tableActions = $('#tblActions').DataTable({....});

This discussion has been closed.