Button enabled if multiple rows selected

Button enabled if multiple rows selected

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

There seems to be no equivalent of

extend: "selectedSingle"

to enable a button only if more than one row is selected. I'm guessing there's a work-around, but I haven't figured it out.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,324Questions: 26Answers: 4,949

    I haven't used that option but I have used something like this example:
    https://datatables.net/extensions/buttons/examples/api/enable.html

    Kevin

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

    But in that example, selecting one row enables both buttons. I want at least two rows to be selected to enable a particular button.

  • kthorngrenkthorngren Posts: 21,324Questions: 26Answers: 4,949

    How about if you change:

            table.button( 0 ).enable( selectedRows === 1 );
            table.button( 1 ).enable( selectedRows > 0 );
    

    To:

            table.button( 1 ).enable( selectedRows > 1 );
    

    This will enable button 1 when 2 or more rows are selected and disable if less than 2 are selected.

    Kevin

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Yup - what Kevin says. You'd need your own buttons.buttons.init function here, which would add an event listener that checks the number of rows selected.

    This is the code that Select uses for its selection event handler.

    Allan

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

    Thank you both! Up, up and away....

This discussion has been closed.