Get specific row data information on click

Tags: #<Tag:0x00007efc64b6cf30>

Hello, is it possible to get the data information from a row where a user clicked on or trying to change? Get only the information from the cell or row was clicked.

Hi @geral

Sure, you can use the [getDataAtRow()]
(https://docs.handsontable.com/pro/1.6.0/Core.html#getDataAtRow) method.

Hereā€™s an example: http://jsfiddle.net/prq8nxbv/
In this example Iā€™m logging data via afterSelection callback but you can also add the same code to afterChange hook as well.

1 Like

Thanks @aleksandra_budnik this helps a lot, one last question, instead getting the value has you show just not, is it possible to get the value when i click inside the cell and than clicked out?Basically just for you to better understand my issue, i need to get the value of a specific row, but then i need to check if that value was changed by the user.

To track if cell was changed you can use the afterChange hook. Hereā€™s the updated demo: http://jsfiddle.net/Lc0sk46g/

Iā€™m logging the row data only if the change wasnā€™t made via loadData. You can add more exceptions like to log the data only when the cell was edited

if(changes === 'edit')

or when new value of the cell is different from the one that was before

if(src[0][2] !== src[0][3])

ps. if you would like yo block a change then itā€™s recommended to choose ā€˜beforeChangeā€™ hook.

hello @aleksandra_budnik this ā€œif(src[0][2] !== src[0][3])ā€ was great, helps a lot it was exactlly what i was looking for, only last question, i tried to get the entire row after and before using var before = this.getDataAtRow(src[0][2]);
var after = this.getDataAtRow(src[0][3]);

But i guess doesnt work this way

Thatā€™s right @geral it doesnā€™t works that way :wink:

As a quick tip

src[0][0] - this is a row of changed cell 
src[0][1] - this is a column of changed cell 
src[0][2] - this is an old value
src[0][3] - this is a new value

while the getDataAtRow() method takes only one argument, which is a row index.

if you would like to get an array of data with old value, you can use beforeChange hook. Hereā€™s an example: http://jsfiddle.net/bdm91eke/

Iā€™m declaring the old variable and in the beforeChange hook Iā€™m filling it with the data from getDataAtRow. At the end Iā€™m logging both tables via afterChange hook.