PDA

View Full Version : Number rounds to two decimals in Property Grid



bbxx
4 Nov 2009, 9:27 PM
I am loading a float into a property grid field, but the default number editor is rounding to 2 decimal points. How do I remove this limitation?



var rec = new Ext.grid.PropertyRecord({
name: fName,
value: new parseFloat(fValue)
});

bbxx
4 Nov 2009, 10:16 PM
I tried to add a custom editor to my property grid now, but it's not quite working. After I try to edit a number field, I get the error from firebug:
this.source is undefined
chrome://firebug/content/blank.gif this.source[record.id] = v;

Then the newly entered number is not displayed. But if I click on the cell to edit again, the new number is there.:-?

What am I doing wrong?




var peoplePropsGrid = new Ext.grid.PropertyGrid({
height: 200,
autoScroll: true,
customEditors: {
'number': new Ext.grid.GridEditor(new Ext.form.NumberField({selectOnFocus:true, decimalPrecision:4, style:'text-align:left;'}))
},
viewConfig : {
forceFit: true,
scrollOffset: 19
}
});

bbxx
4 Nov 2009, 10:51 PM
I think it has something to do with the fact that I didn't use setSource. Instead I used:



peoplePropsGrid.getStore().addSorted(rec);




I tried to add a custom editor to my property grid now, but it's not quite working. After I try to edit a number field, I get the error from firebug:
this.source is undefined
chrome://firebug/content/blank.gif this.source[record.id] = v;

Then the newly entered number is not displayed. But if I click on the cell to edit again, the new number is there.:-?

What am I doing wrong?




var peoplePropsGrid = new Ext.grid.PropertyGrid({
height: 200,
autoScroll: true,
customEditors: {
'number': new Ext.grid.GridEditor(new Ext.form.NumberField({selectOnFocus:true, decimalPrecision:4, style:'text-align:left;'}))
},
viewConfig : {
forceFit: true,
scrollOffset: 19
}
});

bbxx
5 Nov 2009, 12:19 AM
I've reworked my code so that I am using setSource, and now I am not getting any errors. Here is my latest attempt:



myPropCM = Ext.extend(Ext.grid.PropertyColumnModel, {
initComponent : function(){
Ext.grid.EditorGridPanel.superclass.initComponent.call(this);

this.editors = {
'date' : new Ext.grid.GridEditor(new Ext.form.DateField({selectOnFocus:true})),
'string' : new Ext.grid.GridEditor(new Ext.form.TextField({selectOnFocus:true})),
'number' : new Ext.grid.GridEditor(new Ext.form.NumberField({selectOnFocus:true, decimalPrecision:16, style:'text-align:left;'}))
};
}
});

var peoplePropsGrid = new Ext.grid.PropertyGrid({
height: 200,
autoScroll: true,
cm: new myPropCM(),
/*
customEditors: {
'number': new Ext.grid.GridEditor(new Ext.form.NumberField({selectOnFocus:true, decimalPrecision:16}))
},
*/
viewConfig : {
forceFit: true,
scrollOffset: 19
}
});



It's still not working though... It is rounding to 2 significant digits. Can someone point me in the right direction? Thanks

bbxx
5 Nov 2009, 9:20 AM
ok, I finally figured out how to do this after reading through the extjs source code. Hopefully this will help someone else if they google this problem:



Ext.override(Ext.grid.PropertyColumnModel, {
getCellEditor : function(colIndex, rowIndex){
var p = this.store.getProperty(rowIndex),
n = p.data.name,
val = p.data.value;
if(this.grid.customEditors[n]){
return this.grid.customEditors[n];
}
if(Ext.isDate(val)){
return this.editors.date;
}else if(typeof val == 'number'){
if(this.grid.customEditors['number'])
return this.grid.customEditors['number'];
else
return this.editors.number;
}else if(typeof val == 'boolean'){
return this.editors['boolean'];
}else{
return this.editors.string;
}
}
});

var peoplePropsGrid = new Ext.grid.PropertyGrid({
height: 200,
autoScroll: true,
customEditors: {
'number': new Ext.grid.GridEditor(new Ext.form.NumberField({selectOnFocus:true, decimalPrecision:16, style:'text-align:left;'}))
},
viewConfig : {
forceFit: true,
scrollOffset: 19
}
});

yuhanlee
25 Apr 2013, 2:59 AM
seems no one is replying to your thread. But this has helped me. Thanks alot!