Add an event to a cell

Tags: #<Tag:0x00007efc6100e3f8>

Hi!
I’ve a question, is possible add an event listener in one cell to change their value when other cells changed ? for example

Original:
[1][2][3][ ][ ]

Change:
[2][2][3][ ][X ]

this is what I tried a cell config editor.

editor: addEventListener(“keypress”,function(e){
if(!(e.key==13)){
alerta();
}
})

function alerta(){
tabla.updateSettings({
cells: function (row,col){
const cellPrp = {};
if (col === 7 && row === tabla.getSelectedLast()[0]){
cellPrp.renderer = myBtnsAlert;
cellPrp.readOnly = false;
}
return cellPrp;
}
})

Hey @jtacacho

are you thinking about cell dependencies? Here are some great examples on that with demos https://handsontable.com/blog/articles/2016/4/expand-your-app-with-cell-dependencies

You are looking for the afterChange hook. It allows you to track changes of cells and pass setDataAtCell method to change other values.

Thanks a lot !!!

have a nice weekend !

I keep my fingers crossed for further progress :slight_smile:

If you’d need anything feel free to let me know.

I’m experiencing a similar issue. I’m trying to access the data in the table for use in another table.
When I try retrieving the data it comes out as null when I reference the object:

Handsontable.hooks.add(‘afterChange’, (changes) => {
changes.forEach(([row, col, oldValue, newValue]) => {
var salaryData = data[2][2];
// var salaryThis = this.getData(2,2,2,2);
var rowData = this.getCellMeta(2);
var salary = hot.getData(2,2,2,2);
var equity = hot.getData(3,2,3,2)[0];
var bonusPercentage = hot.getData(4,2,4,2)[0];
var refresher = hot.getData(5,2,5,2)[0];
var signOnBonus = hot.getData(6,2,6,2)[0];
console.log(“data at cell”,hot.getDataAtCell(2,2));
console.log(“salaryThis”, rowData);
console.log(“salaryData”,salaryData);
console.log(“salary”,salary);
console.log(“equity”,equity);
calculatedValuation.loadData([companyTitles, calculateFourYearValue(salary, equity, bonusPercentage, refresher, signOnBonus)]);
calculatedValuation.render();
console.log(“changes”, row, col, oldValue, newValue);
});
}, hot);

I tried using this as listed in the article but it seems that the article is outdated as this is not referenced in the event handler. Any ideas how I can retrieve the value I’m looking for?

Hey @gofronm

without a full demo I do not know if hot is actually an instance of Handsontable. Can you share a demo?

I need to close the topic as there’s no response.
If you are still having any issues @gofronm please send over the demo on support@handsontable.com