Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 217
Andreas Jung Avatar asked Feb 14 '12 11:02

Andreas Jung


1 Answers

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.

like image 199
Jpepper Avatar answered Oct 14 '22 12:10

Jpepper