Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqgrid currency formatter

Tags:

jqgrid

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: ','} },
          ],

here in place of thousandsSeparator i want lakhsSeparator.

like image 845
Meraj Avatar asked Jan 17 '23 21:01

Meraj


1 Answers

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

like image 64
Oleg Avatar answered Jan 26 '23 00:01

Oleg