[GH #5051] What is the best way to set type and format for each cell?

I start with an empty table. Users can type integers, floats and text in any cell and also add rows and columns at will. Based on the data in the cells, I’d like to format. For example, no trailing zeroes for integers. For floats, round to two decimals, right align etc.

I tried setting the formats in cells function, but it gets slow, because I’ve to check the data type for each cell and set the styling and formatting accordingly.

Is there a better solution?

Hi @anabayan

How do you differ if a cell is an integer, float or a text? Should the code change the value or just render it in the value you like it to look?

@aleksandra_budnik

Just change the way it looks, not the underlying the data (if that is possible).

My use case is this:

Users start with empty table, and they type/change any value in any cell. I have no way of knowing what value is going to be in a cell. I’d like to put some basic rules in place - if a cell has a number, then right align it and force two decimal places. But if the user changes the same cell to a text, then left align it.

I tried it with “Cells” function - basically tested each value for ints, floats and text and changed the cellProperties object. It works, but for large tables it won’t be usable (like if the user copy pastes 200 cells, then I’ve to check all 200).

Am I doing this wrong?

Apparently, there might be an issue here’ I’ve asked our developer to test it and be back to you with news.

I just got a confirmation that this is a bug related to https://github.com/handsontable/handsontable/issues/4793

We should be able to do it like this http://jsfiddle.net/bn6342es/ but formatting do not apply itself.

I’ve reported it here https://github.com/handsontable/handsontable/issues/5051 and will update you as soon as we fix it.

@aleksandra_budnik

Thank You.
That is what I’ve done so far, but it gets slower for larger tables

Hi @anabayan

I just wanted to update you on the topic of https://github.com/handsontable/handsontable/issues/5051 which has been solved and it is working well in the last stable version 7.4.2