table.rows().select() doesn't work

table.rows().select() doesn't work

embirathembirath Posts: 6Questions: 3Answers: 0

Hi all

I use the Select extension with my datatable. In addition to this, I have custom buttons which allow me to Select All, and Deselect All.

If I use the JQuery addClass('selected') function, my buttons work fine. But the select-info field doesn't get updated showing the number of rows that are currently selected. There is another discussion in the forum about this, and the answer was to use the table.rows().select() instead. But if I use the latter, the rows appear to be selected for just a second, and then they un-select themselves... Can it be that they only stay 'selected' while the button function is active?? Using my browsers "inspect" function, I can see the class being added to the rows, then a second later they disappear...

So, in summary, if I do this, the selection works but select-info field doesn't get updated:

    $('#selectallbutton').click( function () {
        table.$('tr').addClass('selected');
    });

If I do this, the selection doesn't work. The rows get selected, then unselected ~ 1 sec later...

    $('#selectallbutton').click( function () {
        table.rows().select();
    });

This was the old discussion:
https://datatables.net/forums/discussion/34440/how-to-add-pre-selected-rows-into-select-info

Answers

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921

    If I do this, the selection doesn't work. The rows get selected, then unselected ~ 1 sec later...

    Sounds like you have another event or function on your page deselecting the rows. Your code snippet works here:
    http://live.datatables.net/gadojenu/1/edit

    We will need to see what you are doing to help debug. Please post a link to your page or a test case replicating the issue.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • embirathembirath Posts: 6Questions: 3Answers: 0

    Oh my. Silly me, I had the "blurable" option set in the datatables options. If you take your example, and add the blurable option, you'll see that it no longer works. The button is outside of the table body, so of course, it deselects the rows as soon as it selects them.

    Thank you for your example, that helped me track down the issue!!!

    '''
    var table = $('#example').DataTable({
    select: {
    blurable: true,
    },

        });
    

    '''

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921

    Interesting, I've never used that option. Good to know.

    Kevin

This discussion has been closed.