4

I need to force Handsontable to display numbers with a specific format (1.000,01 for example) but it seems to ignore what I try to use as thousands separator.

I tried several ways to do that but none worked :

  • Setting a format to cells that will contain numeric values cell.format = '0.0,00'
  • Setting the same format when instantiating my handsontable object myTable.handsontable({ format: '0.0,00' })
  • Create a locale for numeral.js with delimiters { thousands: '.', decimal: ',' }
  • Changing the format used in a working jsFiddle (from handsontable doc) but I can't get the desired display

Any idea what I'm missing ?

1 Answers1

0

You're right, numeraljs just isn't there yet unfortunately. It works a little better if you use the format using square brackets but it's still not perfect.

Here's a potential format string that seems to work in many cases, but not all:

0.0[,]00 $
ZekeDroid
  • 7,089
  • 5
  • 33
  • 59
  • It doesn't work with Handsontable but when I try to format a number with `numeral().format()` I get the right output... I guess the issue comes from Handsontable rather than numeraljs. – Guillaume Billon Dec 14 '15 at 12:27
  • Really? Because I added that to your fiddle and saw it working which is why I suggested it. But yes, it could also be an issue with Handsontable. A solution would be to implement your own renderer. Attach it to the columns you want modified and use your own formatter, maybe even with an updated version of numeraljs – ZekeDroid Dec 14 '15 at 15:41
  • I tried your solution directly into my project and it didn't work. I just tried it in the fiddle to be sure and I can't get the desired formatted output. To be clear, I typed the wrong format in my first post I'll edit it. – Guillaume Billon Dec 14 '15 at 21:19
  • 1
    Weird, ok well I still suggest the custom renderer then. It's simple enough and should give you a wider range of formatting options. Maybe also file this as a bug on github since it clearly should be working – ZekeDroid Dec 14 '15 at 21:32
  • There's definitely smth that I'm not getting with the formats (like using a dot in the format string and getting a comma in the output) but the custom renderer is working if I use a language with the right separators like `numeral.language('da-dk');` and then use `numeral.format()`. Now the issue is that I use the formula from RuleJS and the value I want to format is '=F9'. I already had this issue when using the afterChange event and I used getCell to get the result. With the custom renderer getCell returns the formula and not the result. How can I get result of the formula in the renderer ? – Guillaume Billon Dec 15 '15 at 16:01
  • I managed to get something that works but it's more of an ugly fix than a solution. Since i can't get the result of the formula with the first rendering I only format the numeric values. Then I render the table a second time to format formula results since I can have them by calling `getCell(row, col).textContent`. If you have a better solution I'm interested, thank you for suggesting the custom renderer with numeraljs. – Guillaume Billon Dec 16 '15 at 09:10