PDA

View Full Version : Why is the store empty?



gnadirap
13 Apr 2010, 2:31 AM
Hi all

I do have a little Store-Problem:

Source


var reader = new Ext.data.JsonReader ({
root: 'user',
id: 'id_user',
fields: [
{name: 'id_user'},
{name: 'first_name'},
{name: 'last_name'},
{name: 'email'},
{name: 'active'}
]
});
var dataStore = new Ext.data.Store({
url: this.ownerModule.app.connection,
baseParams: {
moduleId: this.ownerModule.id,
method: 'readUser'
},
reader:reader,
autoLoad: true,
sortInfo:{field: 'id_user', direction: "ASC"}
});
console.info(dataStore);
var grid = new Ext.grid.GridPanel({
store: dataStore,
sm: new Ext.grid.RowSelectionModel({
singleSelect: false
}),
columns: [
{id: 'id', header: this.language.user.ID, dataIndex: 'id_user', sortable: true, menuDisabled: true, width: 20 },
{id: 'lastname',header: this.language.user.lastname, dataIndex: 'last_name', sortable: true },
{id: 'firstname', header: this.language.user.firstname, dataIndex: 'first_name', sortable: true },
{id: 'active', header: this.language.user.active, dataIndex: 'active', sortable: true, menuDisabled: true,width: 40, renderer: function(value, p, record){return value ? 'Yes' : 'No';}}
],
region: 'west',
width: 280
});
The console output of the Store is empty, but the request returns this:



{'user':[{"id_user":"1","first_name":"Test","last_name":"Test","email":"[email protected]","active":"1"}]}
Can someone please help me and say, why no output is shown either in the console nor the grid?

greeetings

Gnadirap

gnadirap
13 Apr 2010, 10:23 PM
no one?

Please

Greetings

Gnadirap

cog
13 Apr 2010, 11:13 PM
You may want to take a look at:

http://www.extjs.com/deploy/dev/docs/source/Store.html#cls-Ext.data.Store
and
http://www.extjs.com/deploy/dev/docs/source/JsonStore.html#cls-Ext.data.JsonStore

in the api documentation. The second one makes it a lot easier on you ...

gnadirap
14 Apr 2010, 10:26 PM
Thx cog

I now use the JsonStore, configured like the following:



var dataStore = new Ext.data.JsonStore({
url:this.ownerModule.app.connection,
baseParams:{
moduleId: this.ownerModule.id,
method: 'readUser'
},
root:'user',
storeId: 'dataStore',
autoLoad: true,
fields:['id_user','first_name','last_name','email','active']
});


But the Store is still empty

The Request to the URL returns this:



{'user':[{"id_user":"1","first_name":"test","last_name":"test","email":"[email protected]","active":"1"}]}

Animal
14 Apr 2010, 11:05 PM
This question keeps being asked.

It's about once a week now.

And that's because people keep using classes without reading the documentation.

http://www.extjs.com/deploy/dev/docs/?class=Ext.data.Store&member=load

gnadirap
14 Apr 2010, 11:25 PM
But i do have the autoload: true enabled. Why should i also get a PHP-Request and answer from it, if it is not loading?

As I said, the Store loads the function over the BaseParams.
If i now add dataStore.load() i load id twice


var dataStore = new Ext.data.JsonStore({
url:this.ownerModule.app.connection,
baseParams:{
moduleId: this.ownerModule.id,
method: 'readUser'
},
root:'user',
storeId: 'dataStore',
autoLoad: true,
fields:['id_user','first_name','last_name','email','active']
});
dataStore.load();

Animal
14 Apr 2010, 11:29 PM
What you are saying then is "I WON'T read the docs. You have to post the answer for me"

Well that just won't work for you in the long term!

gnadirap
14 Apr 2010, 11:49 PM
I did not say, that i don't read the api documentation. but i just cannot see the problem!

You say, its sometring with the load.. i know it's loaded.. the root is defined, the fields are defined... where's the hint?

steffenk
14 Apr 2010, 11:52 PM
where are you looking for the data, sure it's empty? Add listener:


listeners: {
load: function(store, records, options) {
alert(records.length + ' records loaded');
},

Animal
14 Apr 2010, 11:56 PM
NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

He got away with REFUSING to read the documentation.

So next time he has a problem he gets Steffen to do his work instead of reading the documentation!

steffenk
14 Apr 2010, 11:57 PM
are you sure store is empty? Do you look at the right point?

listeners: {
load: function(store, records, options) {
alert(records.length + ' records are loaded');
}

steffenk
15 Apr 2010, 12:01 AM
Are you sure that there are no records? Do you look at the correct point?

listeners: {
load: function(store, records, options) {
alert(records.length + ' records loaded');
}

Sgt.Pepper
15 Apr 2010, 1:29 AM
I guess Animal was referring to this point of the documentation:


Important: loading is asynchronous! This call will return before the new data has been loaded. So this is the problem:



var dataStore = new Ext.data.Store({
...
autoLoad: true

});
console.info(dataStore); <-- LOAD REQUEST IS STILL IN PROGRESS
try this instead:


var dataStore = new Ext.data.Store({
...
autoLoad: true,
listeners: {
load:function(){
console.info(dataStore);
}
}
});

Animal
15 Apr 2010, 1:44 AM
Correct. The bolded bit with the exclamation point. You can take a horse to water...!

gnadirap
15 Apr 2010, 2:55 AM
oh.. than i'm sorry.. i read it yes.. i also did not understand it.

so i've done it like this:


var dataStore = new Ext.data.JsonStore({
url:this.ownerModule.app.connection,
baseParams:{
moduleId: this.ownerModule.id,
method: 'readUser'
},
storeId: 'dataStore',
root:'user',
idProperty: 'user',
//autoLoad: true,
fields:['id_user','first_name','last_name','email','active'],
listeners: {
load:function(){
console.info(dataStore);
}
}

});
dataStore.load();


but now, it does not show any store at all.. maybe it sounds stupid from my side...

sorry guys i dont understand that.. because in an other file, i have a GroupingStore and it's working problery..

ExampleCode of the GroupingStore:


var store= new Ext.data.GroupingStore({
url: this.ownerModule.app.connection,
baseParams: {
moduleId: this.ownerModule.id,
method: 'loadModules'
},
reader:reader,
autoLoad: true,
sortInfo:{field: 'id', direction: "ASC"},
groupField:'parent'
});

Sgt.Pepper
15 Apr 2010, 4:38 AM
Hmm, maybe your store fires a load exception...

Try this, and tell us which events are generated:



var dataStore = new ...({...});

Ext.util.Observable.capture(dataStore,function(e){
console.log(e);
});

dataStore.load()

gnadirap
15 Apr 2010, 4:53 AM
hi Sgt.Pepper

here is the printscreen of the firebux:

19918

and here the code, with your addon:



var dataStore = new Ext.data.JsonStore({
url:this.ownerModule.app.connection,
baseParams:{
moduleId: this.ownerModule.id,
method: 'readUser'
},
storeId: 'dataStore',
root:'user',
idProperty: 'user',
//autoLoad: true,
fields:['id_user','first_name','last_name','email','active'],
listeners: {
load:function(){
console.info(dataStore);
}
}

});
Ext.util.Observable.capture(dataStore,function(e){
console.log(e);
});
dataStore.load();

Sgt.Pepper
15 Apr 2010, 5:08 AM
well then there is your explanation why your store is empty: You have an exception during load.

Now be creative :)
Add an exception handler to your store, get the error message and see what exactly fails:


var dataStore = ...({
...
listeners: {
'exception': function ( ){
console.log(arguments)
}
}

});

gnadirap
15 Apr 2010, 5:17 AM
Oh.. okay.. indeed there is an exception.. i'm now analysing it.. i will respond, what it was..

gnadirap
15 Apr 2010, 5:37 AM
Refering to my last Picture in beforeload is no Error.

in the load exception And the normal exception it's this failure

19920

mostlikely it's an ',' error somewhere in the code. i'm on the way searching it..( i do not have any other clou)

gnadirap
16 Apr 2010, 12:44 AM
Is it possible to see, what the ajax request returns to the store? like this:



listeners: {
load:function(){
console.info(dataStore);
console.info(responseText);
}
}

steffenk
16 Apr 2010, 2:47 AM
sry for my 3 same posts - they are captured by spam filter.

If you have an exception you won't reach the load listener. if you are in load listener, the store has loaded the data.

So solve your problem, should be on server side. take your json out of FB console and examine with jsonlint.

gnadirap
16 Apr 2010, 5:01 AM
hi

I did it.. here is my Store code, which is working:



var dataStore = new Ext.data.Store({
reader: new Ext.data.JsonReader ({
root: 'user',
id: 'id_user',
fields: [
{name: 'id_user'},
{name: 'first_name'},
{name: 'last_name'},
{name: 'email'},
{name: 'active'}
]
}),
proxy: new Ext.data.HttpProxy ({
scope: this,
url: this.ownerModule.app.connection
}),
baseParams: {
method: 'readUser',
moduleId: this.ownerModule.id
},
autoLoad: true,
listeners: {
load:function(){
console.log(dataStore);
},
exception: function (){
console.log(arguments);
},
loadexception: function(){
console.log(arguments);
}
}
});

Mike Robinson
16 Apr 2010, 6:18 AM
p.s. You might find it useful to know that if a fields entry merely needs the name and nothing else, it can be represented by a string instead of a hash with a single key. It's up to you.