How to show percentage instead of ratio in handsontable?-open source projects handsontable/handsontable

ZekeDroid

I ran into a similar problem myself and have an untested solution. Let me tell you what’s known so far. Handsontable has an Editor and a Renderer. The Editor mimics your data so if you put in 0.5 then whenever you’re editing that cell it will display just that. The Renderer is what you see after you leave the cell, in your case you formatted that value so 0.5 will show up as 50%. This value is for show only and as you’ve pointed out, numeraljs multiplies by 100 and adds a %.

What you’re looking for, however, is a way to essentially keep the data array as 0.5, but on editing change it to 50, and on rendering, leave as 50%.

Here is a solution:

Using an event on Edit, look at the value of the cell. If it is below 1, multiply by 100 (this will change the real value so we have to adjust later). On afterChange, if the value is greater than 1, divide by 100, otherwise leave (the user might’ve blanked out and put in 0.5 again so if you don’t have this check, the value will go down to 0.005).

Note that in the other case that Excel provides, the user might’ve entered 50 to begin with so this method will actually modify this and ALWAYS leave the data array with the value 0.5. If this isn’t what you wanted then things get harder to do so let’s say this is acceptable for now.

That should do the trick though I haven’t tested it and there may be edge cases that I’d love to hear about.

Let me know if it worked and in the meantime