jqgrid currency formatter

后端 未结 2 1866
遇见更好的自我
遇见更好的自我 2020-12-17 05:38

In Jqgrid for currency formatter there is only thousandsSeparator is available but i want lakhsSeparator

colModel: [
            {name: \'Code\', index: \'Co         


        
2条回答
  •  隐瞒了意图╮
    2020-12-17 05:42

    I find the question very interesting. I suggest don't implement the Globalize plugin. Here and here you can find additional information about it.

    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);
    }
    

    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);
            }};
    

    and use there in colModel like

    { name: 'amount', index: 'amount', width: 150, template: currencyTemplate },
    { name: 'age', index: 'age', width: 52, template: numberTemplate },
    

    The demo uses "en-IN" locale and display results like on the picture below

    enter image description here

提交回复
热议问题