PDA

View Full Version : How to read the field type of fields in a store



Michael710
26 Jan 2012, 7:28 AM
All,

I am trying to write a dynamic data grid for EXT JS4 and need to read the data type of a field in a data store. Something like:

Store.fields[0].type orStore.fields[0].getType();

I cannot seem to find what I need. Does anyone have any ideas?

Thanks,

jay@moduscreate.com
26 Jan 2012, 8:09 AM
fields are defined in the model as an instance of MixedCollection


record.fields.each(function(field) {
console.log(field.type);
});

should work,

tvanzoelen
26 Jan 2012, 8:10 AM
yeah that function would be nice, I keep my field meta data in a hash with the grid so I am able to search it quickly.

But you can reach it as follows I quess



function typeLookup(store, fieldname)
{
var rec = new store.model();
var fieldtype = rec.fields.map[fieldname].type.type;
return fieldtype;
}


The pain is, you must have an instance of the model...

Michael710
31 Jan 2012, 5:55 PM
I was able to do the following based on the suggestions:

var fieldcount = rec.fields.getCount();


var xfieldtype;
var xfieldname;


for(x = 0; x < fieldcount; x++){
xfieldtype = rec.fields.getAt(x).type.type;
xfieldname = rec.fields.getAt(x).name;


switch(xfieldtype){
case "date":
jsenc = jsenc + formatDate(updrecords[0].get(xfieldname)) + "||";
break;
case "bool":
if(updrecords[0].get(xfieldname).toString()=='true'){
jsenc = jsenc + "1" + "||";
}else{
jsenc = jsenc + "0" + "||";
}
break;
default:
jsenc = jsenc + updrecords[0].get(xfieldname) + "||";
}

}