Our blazing fast Grid component built with pure JavaScript


Post by Vandana Ojha »

I have a number type column for which I have provided locale based formatting but when I edit that column it shows NaN for some locales (like Swedish, Finnish etc) when there is some negative value in that column (like -1200.58) and also it doesn't allow to enter '-' So I cannot enter negative amount in number type columns whereas it works fine for locale 'en-US'.

I have config similiar to given below:

{ 
   type : 'number', 
   field : 'score', 
   text : 'NumberColumn',
   format:  new NumberFormat({
        locale: 'sv-SE',
        fraction: [0,2],
    }), 
   renderer: ({ value, cellElement, column }) => {
			cellElement.style.backgroundColor = '#faffbd';
			return column.format.format(value);
    },
 }

Any ideas what I'm doing wrong?

Thanks
Vandana Ojha


Post by pmiklashevich »

Hello,

Regarding the typing minus to the NumberField, ticket here: https://github.com/bryntum/support/issues/2235

Also I found a problem with specifying NumberFormat for the NumberColumn.format, ticket here: https://github.com/bryntum/support/issues/2237

when I edit that column it shows NaN for some locales like Swedish when there is some negative value in that column like (-1200.58)

I cannot reproduce the issue. Please try in our Grid Basic example.

Grid/examples/basic/app.js

import NumberFormat from '../../lib/Core/helper/util/NumberFormat.js';

const formatter = new NumberFormat({
    locale   : 'sv-SE',
    fraction : [0, 2]
});

console.log(formatter.format(-1200.58));
// en-US: -1,200.58
// sv-SE: −1 200,58

new Grid({
.......
    columns : [
        {
            type     : 'number',
            width    : 250,
            field    : 'score',
            text     : 'NumberColumn',
            renderer : ({ value, cellElement }) => {
                return formatter.format(value);
            }
        },

Then open the demo locally, double click the first cell to open cell editor, type "0", then click on the arrow down to get "-" and enter "1200.58" so you should see "-1200.58" in the field. Save value. See, it is formatted:

Снимок экрана 2021-01-13 в 15.18.42.png
Снимок экрана 2021-01-13 в 15.18.42.png (40.54 KiB) Viewed 1107 times

Please produce a runnable testcase showing the issue.

Best regards,
Pavel

Pavlo Miklashevych
Sr. Frontend Developer


Post by Vandana Ojha »

Thanks for your reply.

The code and steps mentioned above does the formatting of the cell content using renderer it does not force any formatting while edit So it is working fine the problem is when formatting is there in edit mode also and cell contains negative value then when cell is edited it shows NaN.

Steps to reproduce in Grid Basic example

  1. Please add
    format: new NumberFormat({locale: 'sv-SE', fraction:[0,2]}),
    to any number type column so that formatting is there in edit mode also.
  2. Add any negative value then save
  3. Again edit cell you will see NaN
    OR
    Enter 0 in cell then click on down arrow you will see NaN.

Don't know what the problem is but here : https://www.bryntum.com/docs/grid/#Grid/column/NumberColumn please just add

format: new NumberFormat({locale: 'sv-SE', fraction:[0,2]}),

in the numbercolumn(score) of live demo code and then You will notice

  1. Anyhow you cannot add Negative number
  2. enter 0 then click down arrow NaN will appear

Post by pmiklashevich »

Reproduced with our bundles. Updated 2237 above. Thank you for the report!

Pavlo Miklashevych
Sr. Frontend Developer


Post Reply