Reputation: 1724
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
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
Reputation: 232
Use a listener. When value is changed you format it.
Now to format it:
newValue = "12345678";
newValue.replace(/(\d)(?=(\d{3})+$)/g, '$1,');
// 12,345,678
Upvotes: 0