I want to make a function that changes the background color of td dynamically if the values of the two cells are different from each other.
Currently, there are already two other functions in the cell, is there a way to create a function without any error due to overlapping these two functions?
I’ve done something like this https://jsfiddle.net/o9fLgsp3/2/, and I guess that it meets the requirements. The red background has a higher priority than the comparison logic. Is that correct?
The function of turning the background color red above 225 should be applied to individual cells, but two cells have different values, making the background color yellow should not be applied to each cell, but two cells should be operated at the same time.
For example, if A1=20, B1=20, the background color should be gone, and if A1=20, B1=40, both cells should be yellow.
OK, then please check this one https://jsfiddle.net/2Lbvkx9p/8/. It is not the most optimal way of coding, but it shows what is going on in the afterChange hook. I am manipulating classes of a row of change when the user changes a value in the first column. If you want to add the same actions for the 2nd column, you just need to attach the same logic for column === 1.
Does that meet the requirements now?
When you add the same logic for both columns, you will get https://jsfiddle.net/cpghyq0e/. The afterChange logic gets a lot of code repetition.
It will work. That’s not an issue. But it just does not look good. Ideally, I guess you could create a function that takes row index, column index, and a class name string and just run that for some conditions. But this is just a matter of writing style (nothing to do with the way Handsontable works).