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
和 unformatter 使用 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
之类的地方使用
and use there in colModel
like
{ 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屋!