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.
Get specific row data information on click
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.
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
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.