jqGrid: Number format with comma as decimal point
Asked Answered
F

1

8

I am using the 'number' type for entering floating point numbers into a jqGrid grid. I am able to format the floats for rendering witha comma (we use a comman in Europe as decimal seperator). However the input fields (edit form or inline) still assume that that entered floating point numbers use a dot and not a comma.

formatoptions: {decimalSeperator : ','}

seems to influcence the rendering but not the validation of the input data.

Any reasonable options here?

Fanion answered 14/2, 2012 at 11:53 Comment(1)
I think, The spelling of the word "seperator" is not correct. Modify spelling as "separator"Output
S
7

You can create your own custom formmaters.

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_formatter

The guide explains it well. You must create a formmater and an unformmater for editing.

Create a formatting function like this:

<script>
    jQuery("#grid_id").jqGrid({
    ...
       colModel: [ 
          ... 
          {name:'price', index:'price', width:60, align:"center", editable: true, formatter:numFormat, unformat:numUnformat},
          ...
       ]
    ...
    });

    function numFormat( cellvalue, options, rowObject ){
        return cellvalue.replace(".",",");
    }

    function numUnformat( cellvalue, options, rowObject ){
        return cellvalue.replace(",",".");
    }
</script>

You can also append $ or other formatting in these functions.

Sacchariferous answered 27/2, 2012 at 17:26 Comment(3)
Nota Bene: Thousand separator converter is a space for continentals when anglo-saxons use ","Nubbin
That would not answer the question given by the owner of the question.Sacchariferous
That is why it is a comment ; if you keep the english thousand's separator, you will get a nonsense for any number notation, e.g. 12,345,678.9 -> 12,345,678,9 instead of the correct (and owner requested) 12345678,9Nubbin

© 2022 - 2024 — McMap. All rights reserved.