jqgrid货币格式化程序 [英] jqgrid currency formatter
问题描述
在用于货币格式化程序的Jqgrid中,只有数千个分隔符可用,但我想要lakhsSeparator
In Jqgrid for currency formatter there is only thousandsSeparator is available but i want lakhsSeparator
colModel: [
{name: 'Code', index: 'Code', width: 55, editable: true, sortable: true },
{ name: 'Ammount', index: 'Ammount', width: 100, editable: true, sortable: false, formatter: 'currency', formatoptions: { prefix: '($', suffix: ')', thousandsSeparator: ','} },
],
在这里我需要lakhsSeparator来代替数千个分隔符.
here in place of thousandsSeparator i want lakhsSeparator.
推荐答案
我发现这个问题非常有趣.我建议不要实现 Globalize 插件. 此处和
I find the question very interesting. I suggest don't implement the Globalize plugin. Here and here you can find additional information about it.
用法将很简单.应该定义自定义格式程序,它使用Globalize.format
和使用Globalize.parseFloat
函数的取消格式化程序.例如
The usage will be simple. One should define custom formatter which uses Globalize.format
and unformatter which uses Globalize.parseFloat
functions. For example
formatter: function (v) {
// uses "c" for currency formatter and "n" for numbers
return Globalize.format(Number(v), "c");
},
unformat: function (v) {
return Globalize.parseFloat(v);
}
为了更加舒适,我建议定义numberTemplate
和currencyTemplate
例如
For more comfort I would recommend to define numberTemplate
and currencyTemplate
for example like
var numberTemplate = {align: 'right', sorttype: 'number', editable: true,
searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni']},
formatter: function (v) {
return Globalize.format(Number(v), "n");
},
unformat: function (v) {
return Globalize.parseFloat(v);
}},
currencyTemplate = {align: 'right', sorttype: 'number', editable: true,
searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni']},
formatter: function (v) {
return Globalize.format(Number(v), "c");
},
unformat: function (v) {
return Globalize.parseFloat(v);
}};
并在colModel
之类的地方使用
{ name: 'amount', index: 'amount', width: 150, template: currencyTemplate },
{ name: 'age', index: 'age', width: 52, template: numberTemplate },
演示使用"en-IN"语言环境并显示类似下图
The demo uses "en-IN" locale and display results like on the picture below
这篇关于jqgrid货币格式化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!