Tabulator: Clear cell on cell editing

Created on 10 Apr 2018  路  7Comments  路  Source: olifolkerd/tabulator

I need to clear cell on cell editing if it's value is 0.

        cellEditing:function(cell){
            var value = cell.getValue();
            if (value == 0){
                cell.setValue("", false);
            } 
        },

After cell.setValue() cellEdited callback is calling and trying to save empty value on server.
How can i change cell value without calling cellEdited callback?

Question - Ask On Stack Overflow

All 7 comments

Hey @MusinAmir

To update values of an edit you should be using an Edit Mutator not the cellEditing callback.

That would prevent the callback loop you have been having.

If you can wait a couple of days, the mutator system has had an overhaul for 3.5 so there will be loads more functionality when it is released later this week.

Cheers

Oli :)

Hey @olifolkerd
I don't know how i missed this, this is very useful!

Unfortunately this doesn't fit me, it's working after editing, but i need before editing starts

what do you mean you need it before?

Please go into more detail about what you are trying to achieve and when any other functionailty you have implemented is being called.

Cheers

Oli :)

I have table for planning hours (all editable cells is numbers).
For more comfortable input i need to clear value if it's zero, if i don't do this user will type numbers after 0, like this:
image

What i'm trying to acheive:
When user starts editing a cell clear its value if it's zero.

if (value == 0)
  return "";

After cellEdited if value is empty set zero value.

ahh, i think i follow you.

So this really comes down to whether you want to store the values in the table as a 0 or as an empty string.

If you want to store them as a zero then have you thought about a custom editor that will clear out the cell if the value is 0 when the user clicks on it.

If you want to store them as an empty string then you should use a mutator to mutate the data as it is loaded into the table, and when it is edited to convert 0's to an empty string, and then use a formatter on the cells to show empty strings as 0's

I hope that helps,

Cheers

Oli :)

Hey @olifolkerd
You are a genius! :)
I tried to store zero value as empty string and formatting it to zero, it's works perfectly.
This is exactly what I needed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KES777 picture KES777  路  3Comments

soo1025 picture soo1025  路  3Comments

c3pos-brother picture c3pos-brother  路  3Comments

Manbec picture Manbec  路  3Comments

tomheaps picture tomheaps  路  3Comments