Button enabled if multiple rows selected

Button enabled if multiple rows selected

tangerinetangerine Posts: 3,115Questions: 25Answers: 365

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: 13,816Questions: 25Answers: 3,252

    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,115Questions: 25Answers: 365

    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: 13,816Questions: 25Answers: 3,252

    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: 54,714Questions: 1Answers: 8,560 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,115Questions: 25Answers: 365

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

This discussion has been closed.