closest function, not working

closest function, not working

Coder102Coder102 Posts: 78Questions: 2Answers: 0
edited October 2020 in Free community support

http://live.datatables.net/tivipaxe/1/edit

Hello, my idea is that when I click on "btnChart" it will show me in the console the data of the row that you clicked

i would like to show clo1, col2 and col3

BTN CHART IS IN THE ACTION COLUMN

Replies

  • colincolin Posts: 15,163Questions: 1Answers: 2,588
    edited October 2020

    THere's a few things wrong there - but this should get you going - http://live.datatables.net/cedurofe/1/edit

    The important bit is

    var tr = $(this).closest("tr");
    

    Colin

  • kthorngrenkthorngren Posts: 20,372Questions: 26Answers: 4,780
    edited October 2020

    document.getElementsByClassName("btnChart").onClick=function(e){

    The problem is the event isn't firing. Not sure this method will work. If you want to use DOM elements to create you events this SO thread may help. However I'm not sure if they will work with Datatables when changing pages. See this FAQ for more info.

    You can use jQuery delegated events as shown in this example. I updated your test case to show this:
    http://live.datatables.net/datuyafi/1/edit

    Also note that you need to use cell().render() to get the rendered data. I show how in the example.

    Kevin

  • Coder102Coder102 Posts: 78Questions: 2Answers: 0
    edited October 2020

    I appreciate the help always. Thank you so much guys

This discussion has been closed.