user2665694
user2665694

Reputation:

jqGrid: Number format with comma as decimal point

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?

Upvotes: 8

Views: 19513

Answers (1)

Jpepper
Jpepper

Reputation: 437

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.

Upvotes: 7

Related Questions