Morteza Malvandi
Morteza Malvandi

Reputation: 1724

How show number 2000000 as 2,000,000 in Extjs number field

I'm developing an app with extjs-6. I have a numberfield as follow:

{
      xtype: 'numberfield',
      name: 'rent',
      minWidth: 150,
      allowBlank: true,
    keyNavEnabled: true,
    mouseWheelEnabled: true,
    hideTrigger: true,
}

The number that users must enter is a big number like 20000000. I want to this number show like 20,000,000. How can I do it?

Upvotes: 0

Views: 104

Answers (2)

bakamike
bakamike

Reputation: 1024

You can also use the built in Ext Format method.

{
    xtype : 'textfield',
    listeners : {
        blur : function(t) {
            var val = t.getValue();
            val = val.replace(/,/g, '');
            t.setValue(Ext.util.Format.number(val, '0,000'));
     }
 }

Upvotes: 1

IamSilviu
IamSilviu

Reputation: 232

Use a listener. When value is changed you format it.

Ext.field.Number-event-change

Now to format it:

newValue = "12345678";
newValue.replace(/(\d)(?=(\d{3})+$)/g, '$1,');
// 12,345,678

Upvotes: 0

Related Questions