javascript jqGrid:以逗号为小数点的数字格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9276375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 06:08:31  来源:igfitidea点击:

jqGrid: Number format with comma as decimal point

javascriptjqgrid

提问by Andreas Jung

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.

我正在使用“数字”类型将浮点数输入到 jqGrid 网格中。我能够格式化浮点数以使用逗号进行渲染(我们在欧洲使用逗号作为十进制分隔符)。然而,输入字段(编辑表单或内联)仍然假定输入的浮点数使用点而不是逗号。

formatoptions: {decimalSeperator : ','}

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

似乎影响渲染但不影响输入数据的验证。

Any reasonable options here?

这里有什么合理的选择吗?

采纳答案by Jpepper

You can create your own custom formmaters.

您可以创建自己的自定义格式器。

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

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.

该指南解释得很好。您必须创建一个formmater 和一个unformmater 进行编辑。

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.

您还可以在这些函数中附加 $ 或其他格式。