Best approach to have a button in every row?

Best approach to have a button in every row?

KarloKarlo Posts: 34Questions: 10Answers: 0

Hi!

I'm looking for a way to have a button in each DataTable row. I didn't find this built-in, so I created this fiddle using an unbound column with defaultContent set to some html markup:
https://jsfiddle.net/wxvwx066/

Can you please have a look and tell me if this is good or whether there's a better way?

Thanks!
Karlo

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,642Questions: 1Answers: 10,093 Site admin
    Answer ✓

    I would suggest using a renderer with a delegated event handler. However, the approach you have taken is absolutely valid as well.

    Allan

  • techcheesetechcheese Posts: 1Questions: 0Answers: 0

    hello am using the buttons to redirect to one of my routes of my app. I would like each row to have two buttons that redirect to different route that depend on the data in the Row. This method worked wonderfully for one button, but when i try to add a second i get an error any idea how i can fix it?

  • kthorngrenkthorngren Posts: 20,268Questions: 26Answers: 4,764
    edited April 2020

    @techcheese In order for us to help we will need to see your code. Please provide a running test case showing the issue so we can offer suggestions.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    This thread also has some examples with multiple buttons in a column.

    Kevin

This discussion has been closed.