I have handsontable where I have added a custom button in 2nd column, on click of that I want to send the data of that row to server for processing.
so I have written a onClick function for the button. But how to pass the row index of current row to this function is something I am not able to find out.
var data = [
['', 'Kia', 'Nissan', 'Toyota', 'Honda'],
['<button onClick="edit(this)">Actual</button>', 5, 10, 12, 13],
['<button>2015</button>', 15, -11, 14, 13],
['<button>2016</button>', 20, 15, -12, 'readOnly']
],
columns: [{renderer: "html"}, {type: "text"}, {type: "text"}, {type: "text"}],
Please refer below fiddle to see the code.
You can use hot.getSelected()
. The response is an array of 4 values. The first is the row index, the second is the column index. You could use those in your edit
function. Just call on hot.getSelected()
and it should give you the index assuming the click of the button doesn't stop handsontable from selecting that cell.