dtex-lab
2 Jul 2010, 5:33 AM
Hi,
when browser's language is setted in Italian (and for all those others languages that has comma as decimal separator) in my opinion is there an Ext.util.Format.number issue.
To see it set the browser's language in Italian an run my simple example
Fields description:
1) Format: the format needed by Ext.util.Format.number function
2) Number: the number to be formatted
3) Formatted: the formatted number after the button click.
Test case
I need a grid column that renders a number as so when it is > 0 or renders it with an empty value
if it is == 0
Type /i in 'Format' field (this is what the documentation says)
Type 10 in Number filed
Click to button
The result is an empty string
The Excepted result is 10 and I can get it only if
a) I do not type nothing in 'Format' field
This does not works within the Number 0: The excepted result without nothing in Format field within the
number 0 is an emtpy String but I have 0
b) Typing 0/i in format field
This allows me to handle also the decimal formats but for number 0 I get always 0
For solve this in my render function I had written this code:
numberRender: function (aValue, aFormat, metaData, record, rowIndex, colIndex, store) {
// for empty value the rendered value is always ''
if (!aValue || String(aValue).trim() == '') {
return '';
}
// For number 0 and with a format that does not requires 0 the rendered value is always ''
if (aValue * 1 == 0 && aFormat.indexOf('0') < 0) {
return '';
}
var vOffset = aFormat.indexOf(".");
if (vOffset < 0) vOffset = aFormat.indexOf(",");
// For integer value the rendered value is always the value
if (vOffset < 0) {
return aValue;
}
else {
// I had also to manage the separator because with langue setted in Italian the broewser return numbers with comma as decimal separator
if (DECIMAL_SEPARATOR != '.') {
aValue = String(aValue).replace(DECIMAL_SEPARATOR, ".");
}
// at least I can call for the format number function
return Ext.util.Format.number(aValue, aFormat);
}
}
Here is the code to test it
Ext.onReady(function () {
var vView = new Ext.Viewport({
renderTo: 'test-body',
layout: 'form',
items: [{
xtype: 'field',
id: 'Format',
fieldLabel: 'Format',
}, {
xtype: 'field',
id: 'Number',
fieldLabel: 'Number',
}, {
xtype: 'button',
text: 'click here to format',
id: 'btn',
listeners: {
'click': function (aBtn, aEvt) {
var vMask = Ext.getCmp('Format').getValue();
var vNum = Ext.getCmp('Number').getValue();
var vOutFld = Ext.getCmp('Formatted');
vOutFld.setValue(Ext.util.Format.number(vNum, vMask));
}
}
}, {
xtype: 'field',
id: 'Formatted',
fieldLabel: 'Formatted',
disabled: true
}]
});
});
when browser's language is setted in Italian (and for all those others languages that has comma as decimal separator) in my opinion is there an Ext.util.Format.number issue.
To see it set the browser's language in Italian an run my simple example
Fields description:
1) Format: the format needed by Ext.util.Format.number function
2) Number: the number to be formatted
3) Formatted: the formatted number after the button click.
Test case
I need a grid column that renders a number as so when it is > 0 or renders it with an empty value
if it is == 0
Type /i in 'Format' field (this is what the documentation says)
Type 10 in Number filed
Click to button
The result is an empty string
The Excepted result is 10 and I can get it only if
a) I do not type nothing in 'Format' field
This does not works within the Number 0: The excepted result without nothing in Format field within the
number 0 is an emtpy String but I have 0
b) Typing 0/i in format field
This allows me to handle also the decimal formats but for number 0 I get always 0
For solve this in my render function I had written this code:
numberRender: function (aValue, aFormat, metaData, record, rowIndex, colIndex, store) {
// for empty value the rendered value is always ''
if (!aValue || String(aValue).trim() == '') {
return '';
}
// For number 0 and with a format that does not requires 0 the rendered value is always ''
if (aValue * 1 == 0 && aFormat.indexOf('0') < 0) {
return '';
}
var vOffset = aFormat.indexOf(".");
if (vOffset < 0) vOffset = aFormat.indexOf(",");
// For integer value the rendered value is always the value
if (vOffset < 0) {
return aValue;
}
else {
// I had also to manage the separator because with langue setted in Italian the broewser return numbers with comma as decimal separator
if (DECIMAL_SEPARATOR != '.') {
aValue = String(aValue).replace(DECIMAL_SEPARATOR, ".");
}
// at least I can call for the format number function
return Ext.util.Format.number(aValue, aFormat);
}
}
Here is the code to test it
Ext.onReady(function () {
var vView = new Ext.Viewport({
renderTo: 'test-body',
layout: 'form',
items: [{
xtype: 'field',
id: 'Format',
fieldLabel: 'Format',
}, {
xtype: 'field',
id: 'Number',
fieldLabel: 'Number',
}, {
xtype: 'button',
text: 'click here to format',
id: 'btn',
listeners: {
'click': function (aBtn, aEvt) {
var vMask = Ext.getCmp('Format').getValue();
var vNum = Ext.getCmp('Number').getValue();
var vOutFld = Ext.getCmp('Formatted');
vOutFld.setValue(Ext.util.Format.number(vNum, vMask));
}
}
}, {
xtype: 'field',
id: 'Formatted',
fieldLabel: 'Formatted',
disabled: true
}]
});
});