View Full Version : 'Ext.data.Record.create' and 'type: auto' for numbers

16 Aug 2007, 7:24 AM
Hello! :)

I'm having fun with the Editor Grid Example from the Ext Documentation Center.

I copied the following code and changed it to my needs:

var Plant = Ext.data.Record.create([
{name: 'A', mapping: 'a'},
{name: 'B', mapping: 'b', type: 'int'},
{name: 'C', mapping: 'c', type: 'string'},

Now, column 'B' has contents that are like '001' or '014' - always with one or two leading '0'.

Setting the 'type' to be 'int' isn't a good idea because the leading 0's are removed so I would need to set the 'type' to be 'number' but the following code doesn't work. :(

var Plant = Ext.data.Record.create([
{name: 'A', mapping: 'a'},
{name: 'B', mapping: 'b', type: 'number'},
{name: 'C', mapping: 'c', type: 'string'},

Am I safe when I go for 'type: 'auto'' even though it's really a number I want to display? :)

Thanks for your time and patience. Ext JS rocks! :)

19 Sep 2007, 5:36 AM
I am having this same problem.

What id did to get around it is append an character to the end of the value and then with a renderer defined on the column model i strip off that character. It's not ideal but at least it's a work around..

And I do believe that this should be a feature as it is needed.

19 Sep 2007, 5:46 AM
I think it really is a string you want to display if you want the leading zeroes perserved.

19 Sep 2007, 5:50 AM
I have it set to a string yet it still strips off the leading 0 from the value

ds: new Ext.data.Store({
reader: new Ext.data.JsonReader({
root: 'Items',id: 'car_id', success: "success"}, [
{name: 'id', mapping: 'car_id'},
{name: 'car_name'},
{name: 'car_number', type: "string"},
{name: 'car_entrant'},
{name: 'car_strategist'},
{name: 'car_chassis'},
{name: 'car_engine'},
{name: 'car_tire'}
proxy: new Ext.data.HttpProxy({
url: './ajax/getCarsGrid.php'
remoteSort: false,

19 Sep 2007, 6:25 AM
You have to pass the data as a quoted string, otherwise it will just be a number when the JSON is evaluated into an Object, and there will be no leading zeroes on a number.

19 Sep 2007, 7:50 AM
OK i figured a way around this.

I had to rewrite my Json PHP encoder to encode any numeric value as a string if it started with a zero and they set the type of the column to be a string and it works just fine now.


see now if i would have refreshed before i wrote this i would have not spend a half hour trying to figure it out... :(