PDA

View Full Version : DataReader ? ? ?



merianos
18 Jul 2009, 3:34 AM
Hello all !

I'm very new on ExtJS and I need your help. :)

I try to create an application witch is devided in two parts.

The first one is the PHP that generating an XML File :



<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-Type: application/xml");

echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<dataset>';
echo '<total>';
echo $total;
echo '</total>';
foreach($data as $dt)
{
echo '<data>';
echo '<id>';
echo $dt['Group']['id'];
echo '</id>';
echo '<name>';
echo $dt['Group']['name'];
echo '</name>';
echo '</data>';
}

echo '</dataset>';
?>


The above code is working perfectly !
It generating the XML correctly;

the XML Code that I'm getting back is the following one :



<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<total>3</total>
<data>
<id>1</id>
<name>Administrators</name>
</data>
<data>
<id>2</id>
<name>Managers</name>
</data>
<data>
<id>3</id>
<name>Users</name>
</data>
</dataset>


The second part is the ExtJS.

Is already installed in my page and I try to load the xml on it but I have problem

The code is the following :



Ext.onReady(
function()
{

var groupDS = new Ext.data.Store(
{
reader: new Ext.data.XmlReader(
{
record: 'data',
id: 'id'
},
[
'id',
'name'
]
),
url: 'http://www.myserveraddress.dch/Groups/view'
}
);

groupDS.load();

var vp = new Ext.Viewport(
{
renderTo: Ext.getBody,
layout: 'border',
items:
[
{
region: 'north',
xtype: 'toolbar',
height: '25',
items:
[
menuToolBar
]
},
{
region: 'west',
margins: '5 0 5 5',
split: true,
width: 280,
closable: true,
layout: 'accordion',
layoutConfig:
{
animate: true,
activeOnTop: false,
fill: true
},
items:
[
{
title: "Users & Groups",
xtype: 'panel',
items:
[
{
title: "Example panel 1",
collapsible: true,
xtype: 'form',
items:
[
{
xtype: "combo",
fieldLabel: "Groups",
name: "groups",
store: groupDS,
mode: 'local',
displayField: 'name'
}
]
},
{
title: "Example panel 2",
collapsible: true,
xtype: 'panel',
height: 200
},
{
title: "Example panel 3",
collapsible: true,
xtype: 'panel',
height: 200
},
{
title: "Example panel 4",
collapsible: true,
xtype: 'panel',
height: 200,
id: 'panel4'
}

]
},
{
title: "Again hello !"
}
]
},
{
region: 'center',
xtype: 'panel',
id: 'Hello'
},
{
region: 'south',
xtype: 'toolbar',
height: '25',
items:
[
statusToolBar
]
}
]
}
);
}
);


The problem is that I can't get the data from the XmlReader and place it into the combo ! !

I have try many methods but It can't work ! ! !

What can I do ? ? ?

Kind regards Merianos nikos

Condor
18 Jul 2009, 3:39 AM
It looks OK (apart from Example panel 1 missng autoHeight:true).

Try adding load and loadexception listeners to the store and see which one fires.

merianos
18 Jul 2009, 3:42 AM
What I have try to do is


var groupDS = new Ext.data.Store(
{
reader: new Ext.data.XmlReader(
{
record: 'data',
id: 'id'
},
[
'id',
'name'
]
),
url: 'http://www.hotelcms.dch/Groups/view',
load: function()
{
alert("Loaded");
}
}
);

and it's working the load

Condor
18 Jul 2009, 3:45 AM
That is not a listener.

Try:

var groupDS = new Ext.data.Store({
reader: new Ext.data.XmlReader({
record: 'data',
id: 'id',
fields: ['id', 'name']
}),
url: 'http://www.hotelcms.dch/Groups/view',
listeners: {
load: function(){
alert("Loaded");
},
loadexception: function(){
alert("Not loaded");
}
}
});

(in Ext 3 it would be better to use the exception intead of loadexception event)

merianos
18 Jul 2009, 3:45 AM
What I have try to do is


var groupDS = new Ext.data.Store(
{
reader: new Ext.data.XmlReader(
{
record: 'data',
id: 'id'
},
[
'id',
'name'
]
),
url: 'http://www.hotelcms.dch/Groups/view',
load: function()
{
alert("Loaded");
}
}
);

and it's working the load


The loadexception does not fire

merianos
18 Jul 2009, 3:47 AM
That is not a listener.

Try:

var groupDS = new Ext.data.Store({
reader: new Ext.data.XmlReader({
record: 'data',
id: 'id',
fields: ['id', 'name']
}),
url: 'http://www.hotelcms.dch/Groups/view',
listeners: {
load: function(){
alert("Loaded");
},
loadexception: function(){
alert("Not loaded");
}
}
});(in Ext 3 it would be better to use the exception intead of loadexception event)

Again with your way the load is the one that works

merianos
18 Jul 2009, 10:19 PM
Any solution to my problem ? ? ?

merianos
18 Jul 2009, 10:20 PM
I wander if I need any Serial Key to use the ExtJS.

I hope tthat I don't need something like that eh ? ? ? ?

Condor
18 Jul 2009, 11:29 PM
No, you don't need a serial key.

Can you look at the parameters passed in the load event handler? How many records are returned?

merianos
19 Jul 2009, 4:05 AM
No, you don't need a serial key.

Can you look at the parameters passed in the load event handler? How many records are returned?
How can I do that ? ? ?

I am very new to ExtJS and I do not have the expirience on how can I do it !

Kind regards
Merianos Nikos

Condor
19 Jul 2009, 10:46 AM
You can find the parameters for the load event in the API docs (http://www.extjs.com/deploy/dev/docs/?class=Ext.data.Store).


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

merianos
19 Jul 2009, 11:28 AM
Thanks a lot for your assistant :)

I already have seen these options but I didn't knew how to use them :)

Thanks a lot again :)

merianos
20 Jul 2009, 12:21 AM
I used the Listener as you show me and return 3 records from the XML file as normaly must be.

As I supose this reader is working properly.

So the problem must be the Grid or something else ! !

But where could be the problem ? ? ?

Is there any other way to debug the grid to see why doesn't load the data from the store ? ? ?

merianos
20 Jul 2009, 12:33 AM
The problem solved with no change.

Is there any posibility to be cached the code and execute the wrong code ? ? ?

In example :

If that is incorect alert('Hello'; the browser will return error.

now if I will change it to alert('Hello'); this is the correct. Is there any posibility to be cached the wrong code and return any time error ? ? ? Or the ExtJS It has this property ? ? ?

Thanks a lot for the assistance :)

Condor
20 Jul 2009, 12:43 AM
All GET requests can be cached., e.g. all .html, .js and .css files without a timeout (or similar) response header.

But this is also true for all files fetched with a XHR request (but if configured correctly, Ext will add a _dc parameter to make every request unique).

merianos
20 Jul 2009, 12:51 AM
All GET requests can be cached., e.g. all .html, .js and .css files without a timeout (or similar) response header.

But this is also true for all files fetched with a XHR request (but if configured correctly, Ext will add a _dc parameter to make every request unique).


And how can I configure out the Ext to stop Caching ? ? ?

Condor
20 Jul 2009, 1:12 AM
For .html, .js and .css (and optionally data) you need to configure your server.

For data you can configure your request with disableCaching:false or nocache:false (depending on what method you use for your request -- see API docs).

merianos
20 Jul 2009, 1:30 AM
For .html, .js and .css (and optionally data) you need to configure your server.

For data you can configure your request with disableCaching:false or nocache:false (depending on what method you use for your request -- see API docs).

Condor you are the best ! ! ! :)

thanks a lot for your assistance :)