Clearing a cell by pressing backspace button sets the cell value to null

Tags: #<Tag:0x00007f0b037d8df8>

Hi all,

I have a requirement that is when a user enters a cell and comes out of it and if cell value is changed then I’ve to dispatch the edited row to the reducer.

When a user enters a cell and comes out of it, the handsontable considers it as an edit. So basically what I’m doing is when we edit a cell, afterChange will be called and in the changes, I compare 3rd and 4th index values of changes array. (That is previous and current value). If they’re same and I don’t dispatch an action to the reducer if they’re not same I dispatch an action.

So here the problem is when we clear a cell using by pressing backspace button it will not add empty string to the cell, instead it will add null to the cleared cell. So if I enter again and come out of that doing anything it considers as an edit has happend because the condition will fail.

So is there any option when backspace button is pressed instead of setting null to the cell set an empty string cell(s)?

Figured it out.

A little block of code I had to write to write an empty string instead of null.

if (changes[0][3] === null) {
    const rowNumber = changes[0][0];
    const columnNumber = this.propToCol(changes[0][1]);
    this.setDataAtCell(rowNumber, columnNumber, "");
}

Glad to see a quick turnaround. I guess that we can close the topic.
Thank you for the update.

1 Like