How to set european format for numbers (comma instead dot) during first creation of the handsontable

Tags: #<Tag:0x00007efc64935bb8>

Hello,

I would like to set european format for numbers (comma instead dot) during first initialization of the handsontable object. I used a following code:

  culture: "de-DE",
  format: '0.0,00',
  pattern: '0.0,00',

Example:
https://jsfiddle.net/janzitniak/bawt3h2e/11/

But in C1 cell I see 0.5 instead 0,5.

EDIT: I know, it’s possible to set up each column like this:

columns: [
    {
      data: 'price_eur',
      type: 'numeric',
      numericFormat: {
        pattern: '0,0.00 $',
        culture: 'de-DE' // use this for EUR (German),
        // more cultures available on http://numbrojs.com/languages.html
      }
    }
]

but I would like to type there any text too, then I get an error.
Jan

Hi Jan! There are a few problems in the first snippet, you need to make two changes:

  1. provide “pattern” and “culture” as properties of “numericFormat” configuration property
  2. set “type: numeric” for the columns or cells where you want to use it or just set it for the whole grid

A fixed demo: https://jsfiddle.net/warpech/k02a1ur7/2/

Dear Marcin, thank you for your quick response and the example. It works, but I need write a text (string) to any cells also. Now it produces an error (red warning in cell). Maybe turn off errors or create own validator …

Hi @jan.zitniak

or create own validator …

that’s the path to follow. Depending on what should be considered valid I propose to use a regex.

Hi @aleksandra_budnik,

thank you for the idea. For this moment I used the simplest way to set up a white color for invalid cells adding css code:

.handsontable table td.htInvalid { background-color:white !important; }

P.S.: Marcin, Aleksandra and to all your colleagues I wish you a happy, healthy New Year! :champagne::four_leaf_clover::heartpulse:

1 Like

Thank you for your wishes, Jan! I hope that this year will be very generous for all of us :slight_smile:

1 Like

Thank you Aleksandra, I very appreciate your positive view :wave:

1 Like