Editable Data Table: How to give a cell a default value if the user hits backspace instead of an empty cell?

So currently when you hit backspace in an editable Data Table, the cell is just going to be empty.
I want to fill the cell automatically with a default value (for example 0).

Now one way to achieve this is maybe to make a callback that has ‘data’ or the timestamp as input and always compare the full table content with the state it was previously in.
But in my case I have a pretty big table and firing a callback and transfering the whole data content over the network whenever a user hits backspace to delete a value seems super inefficient.

It would be really neat if there was a function such as those style conditionals, but for more than just styling…

Does anyone has an idea how to implement such a thing or is this currently not possible?

1 Like

@dimark Good question!

There is a mechanism that coerces & validates data entry in the table but it is not applied when deleting the cells with backspace with either a single or multiple cells selected.

Also just found out that the 0 number default case is not applied correctly because is it falsy and the validation contains a bug.

Opened an issue and a PR to fix those.

Still need to validate the approach, but if/when the fix is added, I expect the following column configuration to give you the desired behavior for both the normal cell-entry validation and when deleting the content of cell(s) through backspace, with the 0 validation default case.

columns=[{
    'id': 'col1',
    'name': 'col1',
    'type': 'numeric',
    'on_change': {
        'action': 'coerce',
        'failure': 'default'
    },
    'validation': {
        'default': 0
    }
}]

For the table’s typing documentation.

1 Like

The fix & change to support this will be in the next release, dash==1.4.0.

Sounds great!
I am looking forward to the next release