View Full Version : Code Syntax Question from Learning EXT JS - Chapter 6

25 Jul 2009, 8:54 AM
I am recreating the examples of creating an editable data grid from the book: Learning EXT JS - chapter 6. I am using a coldFusion 8 server.

In the code example there is a renderer that calls a combo box that maps a genre ID to genre name.

This currently uses a static SimpleStore:

var staticGenres = new Ext.data.SimpleStore({
fields: ['GENREID', 'GENRE'],
data : [[0,'Comedy'],[1,'Drama'],[2,'Action']]
});I have created a Json Store to replace this:

var distinctGenre = new Ext.data.JsonStore({
baseParams:{method: 'getDistinctGenre', returnFormat: 'JSON',start: '1',limit: '50'},
fields: ['GENREID', 'GENRE'],
});The json store returns the following:

{"DATASET":3,"ROWS":[{"GENREID":0,"GENRE":"Comedy"},{"GENREID":1,"GENRE":"Drama"},{"GENREID":2,"GENRE":"Action"}],"STARTROW":1.0,"ENDROW":50.0}The renderer calls: getGenreNameByID

function getGenreNameByID(val){
//Ext.Msg.alert('[val]', val);
return staticGenres.queryBy(function(rec){return rec.data.GENREID == val;}).itemAt(0).data.GENRE;
}And this works fine.

But when I change the function to look at the json store:

function getGenreNameByID(val){
//Ext.Msg.alert('[val]', val);
return distinctGenre.queryBy(function(rec){return rec.data.GENREID == val;}).itemAt(0).data.GENRE;
}Generates the following error:

distinctGenre.queryBy(function (rec) {if (rec.data.GENREID == val) {return true;} else {return false;}}).itemAt(0) is undefinedYou help is appreciated.
Thank you.

25 Jul 2009, 9:01 AM
Asynchronous? Has the data crawled over the wire by the time you query the Store?

25 Jul 2009, 9:23 AM
Thank you. That was it.

I was calling the data stores in the wrong order:
initially I was calling the store for the data grid first and than the store for the editable combo box second.

When I reversed the order, the code worked fine.

Thank you again.