PDA

View Full Version : Grid initial problem XmlReader



galdaka
23 Feb 2007, 2:43 AM
Hi,

My first exmaple with grid, not load:


<SCRIPT type=text/javascript>


Ext.onReady(function(){


var record = Ext.data.Record.create([
{name: 'ClienteT', mapping: 'cliente'},
{name: 'CIFT', mapping: 'cif'},
{name: 'ALBARANT', mapping: 'numAlbaran'},
{name: 'FACTURAT', mapping: 'numFactura'},
{name: 'FECHAT', mapping: 'fecha'},
{name: 'IMPORTET', mapping: 'importe'}
]);


var reader = new Ext.data.XmlReader({
record: 'catalog',
totalProperty: 'totalDocs',
id: 'ID'
}, record);

var ds = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: 'http://...' //See XML above
}),
reader: reader
});

var cm = new Ext.grid.ColumnModel([{
header: "Cliente",
width: 75
},{
header: "CIF",
width: 100
},{
header: "Nº Albarán",
width: 100
},{
header: "Nº Factura",
width: 100
},{
header: "Fecha",
width: 100
},{
header: "Importe",
width: 100
}]);

var grid = new Ext.grid.Grid('example-grid', {
ds: ds,
cm: cm,
selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
enableColLock:false
});

ds.load({params:{vista:'vista01', page:1, pageSize:5}});

});

</script>

<div id="example-grid" class="x-grid-mso" style="border: 1px solid #c3daf9; overflow: hidden; width:520px;"></div>


The call returns valid XML like this:


<?xml version="1.0" encoding="ISO-8859-1" ?>
<catalog>
<entry>
<ID>009EE8C43F035EE6C1257275004ECF35</ID>
<cliente>1062364</cliente>
<cif>68654716K</cif>
<numAlbaran>98H93912214</numAlbaran>
<numFactura>58J95511496</numFactura>
<fecha></fecha>
<importe>850121</importe>
</entry>
<entry>
<ID>00C8B21A1B99B901C1257275004ECD7B</ID>
<cliente>11</cliente>
<cif>68654716K</cif>
<numAlbaran>15H37775445</numAlbaran>
<numFactura>16J20300691</numFactura>
<fecha></fecha>
<importe>146615</importe>
</entry>
<entry>
<ID>01370BEFB56000A9C1257275004ECD78</ID>
<cliente>1062364</cliente>
<cif>68654716K</cif>
<numAlbaran>26H89648116</numAlbaran>
<numFactura>78J66958362</numFactura>
<fecha></fecha>
<importe>376021</importe>
</entry>
<entry>
<ID>018DC7067EFE824EC1257275004ECF39</ID>
<cliente>1062364</cliente>
<cif>68654716K</cif>
<numAlbaran>24H74748880</numAlbaran>
<numFactura>27J50652188</numFactura>
<fecha></fecha>
<importe>449938</importe>
</entry>
<entry>
<ID>01B36E87437566A0C1257275004ECCD0</ID>
<cliente>222233333</cliente>
<cif>68654716K</cif>
<numAlbaran>27H71715850</numAlbaran>
<numFactura>6J27910993</numFactura>
<fecha></fecha>
<importe>435707</importe>
</entry>
<totalDocs>773</totalDocs>
</catalog>

What is the error?

Animal
23 Feb 2007, 2:58 AM
I think you need



var reader = new Ext.data.XmlReader({
record: 'entry',
totalProperty: 'totalDocs',
id: 'ID'
}, record);

galdaka
23 Feb 2007, 3:40 AM
I test with:


var reader = new Ext.data.XmlReader({
record: 'entry',
totalProperty: 'totalDocs',
id: 'ID'
}, record);


var reader = new Ext.data.XmlReader({
record: 'catalog',
totalProperty: 'totalDocs',
id: 'ID'
}, record);


var reader = new Ext.data.XmlReader({
record: 'catalog > entry',
totalProperty: 'totalDocs',
id: 'ID'
}, record);

combining with:


var record = Ext.data.Record.create([
{name: 'ClienteT', mapping: 'entry > cliente'},
{name: 'CIFT', mapping: 'entry > cif'},
{name: 'ALBARANT', mapping: 'entry > numAlbaran'},
{name: 'FACTURAT', mapping: 'entry > numFactura'},
{name: 'FECHAT', mapping: 'entry > fecha'},
{name: 'IMPORTET', mapping: 'entry > importe'}
]);


var record = Ext.data.Record.create([
{name: 'ClienteT', mapping: 'catalog > entry > cliente'},
{name: 'CIFT', mapping: 'catalog > entry > cif'},
{name: 'ALBARANT', mapping: 'catalog > entry > numAlbaran'},
{name: 'FACTURAT', mapping: 'catalog > entry > numFactura'},
{name: 'FECHAT', mapping: 'catalog > entry > fecha'},
{name: 'IMPORTET', mapping: 'catalog > entry > importe'}
]);

and not work, any ideas????

Animal
23 Feb 2007, 3:46 AM
Looking at the source code, I think the record should in fact be be 'catalog > entry' and then you should just need:



var record = Ext.data.Record.create([
{name: 'ClienteT', mapping: 'cliente'},
{name: 'CIFT', mapping: 'cif'},
{name: 'ALBARANT', mapping: 'numAlbaran'},
{name: 'FACTURAT', mapping: 'numFactura'},
{name: 'FECHAT', mapping: 'fecha'},
{name: 'IMPORTET', mapping: 'importe'}
]);

jack.slocum
23 Feb 2007, 3:49 AM
It's your record defs. The query in the mapping will be executed in the scope of the matched "entry" nodes so 'entry > cliente' won't match anything (an entry node does not have a child node of "entry"). Change it to 'cliente' and it should work fine.

galdaka
23 Feb 2007, 5:34 AM
not work, i dont know what is the problem:



<SCRIPT type=text/javascript>


Ext.onReady(function(){


var record = Ext.data.Record.create([
{name: 'cliente', mapping: 'cliente'},
{name: 'cif', mapping: 'cif'},
{name: 'numAlbaran', mapping: 'numAlbaran'},
{name: 'numFactura', mapping: 'numFactura'},
{name: 'fecha', mapping: 'fecha'},
{name: 'importe', mapping: 'importe'}
]);


var reader = new Ext.data.XmlReader({
record: 'catalog > entry',
totalProperty: 'catalog > totalDocs',
id: 'catalog > entry > ID'
}, record);

var ds = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: 'http://bñabñabñabña'
}),
reader: reader
});

var cm = new Ext.grid.ColumnModel([{
header: "Cliente",
width: 75
},{
header: "CIF",
width: 100
},{
header: "Nº Albarán",
width: 100
},{
header: "Nº Factura",
width: 100
},{
header: "Fecha",
width: 100
},{
header: "Importe",
width: 100
}]);

var grid = new Ext.grid.Grid('example-grid', {
ds: ds,
cm: cm,
selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
enableColLock:false
});

ds.load({params:{vista:'vista01', page:1, pageSize:10}});

});

</script>

<div id="example-grid" class="x-grid-mso" style="border: 1px solid #c3daf9; overflow: hidden; width:520px;"></div>

XML:


<?xml version="1.0" encoding="ISO-8859-1" ?>
<catalog>
<entry>
<ID>009EE8C43F035EE6C1257275004ECF35</ID>
<cliente>1062364</cliente>
<cif>68654716K</cif>
<numAlbaran>98H93912214</numAlbaran>
<numFactura>58J95511496</numFactura>
<fecha></fecha>
<importe>850121</importe>
</entry>
<entry>
<ID>00C8B21A1B99B901C1257275004ECD7B</ID>
<cliente>11</cliente>
<cif>68654716K</cif>
<numAlbaran>15H37775445</numAlbaran>
<numFactura>16J20300691</numFactura>
<fecha></fecha>
<importe>146615</importe>
</entry>
<entry>
<ID>01370BEFB56000A9C1257275004ECD78</ID>
<cliente>1062364</cliente>
<cif>68654716K</cif>
<numAlbaran>26H89648116</numAlbaran>
<numFactura>78J66958362</numFactura>
<fecha></fecha>
<importe>376021</importe>
</entry>
<entry>
<ID>018DC7067EFE824EC1257275004ECF39</ID>
<cliente>1062364</cliente>
<cif>68654716K</cif>
<numAlbaran>24H74748880</numAlbaran>
<numFactura>27J50652188</numFactura>
<fecha></fecha>
<importe>449938</importe>
</entry>
<entry>
<ID>01B36E87437566A0C1257275004ECCD0</ID>
<cliente>222233333</cliente>
<cif>68654716K</cif>
<numAlbaran>27H71715850</numAlbaran>
<numFactura>6J27910993</numFactura>
<fecha></fecha>
<importe>435707</importe>
</entry>
<entry>
<ID>01E628A782BD78EEC1257275004ECD5F</ID>
<cliente>1062364</cliente>
<cif>68654716K</cif>
<numAlbaran>33H39663216</numAlbaran>
<numFactura>43J51439679</numFactura>
<fecha>13%2F12%2F2006</fecha>
<importe>826331</importe>
</entry>
<entry>
<ID>024D67DCBBE8F0DFC1257275004ECF7D</ID>
<cliente>10623d64545454</cliente>
<cif>68654716K</cif>
<numAlbaran>11H24553195</numAlbaran>
<numFactura>66J75239086</numFactura>
<fecha></fecha>
<importe>818450</importe>
</entry>
<entry>
<ID>028A3F13B2B41895C1257275004ECE73</ID>
<cliente>15</cliente>
<cif>68654716K</cif>
<numAlbaran>27H37277272</numAlbaran>
<numFactura>21J65466309</numFactura>
<fecha></fecha>
<importe>880740</importe>
</entry>
<entry>
<ID>02985DEBB432432AC1257275004ECDCE</ID>
<cliente>1062364</cliente>
<cif>68654716K</cif>
<numAlbaran>86H67531973</numAlbaran>
<numFactura>86J43700179</numFactura>
<fecha>13%2F12%2F2006</fecha>
<importe>253674</importe>
</entry>
<entry>
<ID>02E4F3C151E3FFCDC1257275004ECCD2</ID>
<cliente>1062364</cliente>
<cif>68654716K</cif>
<numAlbaran>31H63877439</numAlbaran>
<numFactura>32J93980759</numFactura>
<fecha>13%2F12%2F2006</fecha>
<importe>554224</importe>
</entry>
<totalDocs>773</totalDocs>
</catalog>

Any ideas???

Animal
23 Feb 2007, 6:23 AM
Being as it's Alpha code, do what I've been doing for the past few days:

Use ext-all-debug.js, and boldly step into it with Firebug!

jack.slocum
23 Feb 2007, 7:16 AM
var reader = new Ext.data.XmlReader({
record: 'entry',
totalProperty: 'totalDocs',
id: 'ID'
}, record);

All record queries are executed against the root element. It may make sense for me to change that but it results in quite a speed boost.

I recommend keeping the queries as simple as possible, it makes loading much faster.

The id property is executed in the scope of the "entry" like standard fields.

{name: 'cliente', mapping: 'cliente'},

mapping defaults to name, so you if they are the same you don't have to include mapping. In fact, if you don't have any extra properties you can just do it as a string:


var record = Ext.data.Record.create([
'cliente', 'cif', ... etc
]);

galdaka
23 Feb 2007, 7:52 AM
Thanks jack, I will try Monday to first hour and it will comment the results.

I like the new way to make the things with Ext 1.0; this way they will not be needed special readers for different XML´s => using search (root > child1) you will parse all XML´s.

Single I hope that it works ;)

galdaka
26 Feb 2007, 1:04 AM
Hi,


not work, and XMLGrid from alpha2 examples not work for me (IE6). the code:



<SCRIPT type=text/javascript>


Ext.onReady(function(){


var record = Ext.data.Record.create([
{name: 'clienteT', mapping: 'cliente'},
{name: 'cifT', mapping: 'cif'},
{name: 'numAlbaranT', mapping: 'numAlbaran'},
{name: 'numFacturaT', mapping: 'numFactura'},
{name: 'fechaT', mapping: 'fecha'},
{name: 'importeT', mapping: 'importe'}
]);


var reader = new Ext.data.XmlReader({
record: 'entry',
totalProperty: 'totalDocs',
id: 'ID'
}, record);

var ds = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: 'http://blabla.php'
}),
reader: reader
});

var cm = new Ext.grid.ColumnModel([{
header: "Cliente",
width: 75
},{
header: "CIF",
width: 100
},{
header: "Nº Albarán",
width: 100
},{
header: "Nº Factura",
width: 100
},{
header: "Fecha",
width: 100
},{
header: "Importe",
width: 100
}]);

var grid = new Ext.grid.Grid('example-grid', {
ds: ds,
cm: cm,
selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
enableColLock:false
});

ds.load({params:{vista:'vista01', page:1, pageSize:10}});

});

</script>

<div id="example-grid" class="x-grid-mso" style="border: 1px solid #c3daf9; overflow: hidden; width:520px;"></div>

The XML:


<?xml version="1.0" encoding="ISO-8859-1" ?>
<catalog>
<entry>
<ID>009EE8C43F035EE6C1257275004ECF35</ID>
<cliente>1062364</cliente>
<cif>68654716K</cif>
<numAlbaran>98H93912214</numAlbaran>
<numFactura>58J95511496</numFactura>
<fecha></fecha>
<importe>850121</importe>
</entry>

<entry>
<ID>00C8B21A1B99B901C1257275004ECD7B</ID>
<cliente>11</cliente>
<cif>68654716K</cif>
<numAlbaran>15H37775445</numAlbaran>
<numFactura>16J20300691</numFactura>
<fecha></fecha>
<importe>146615</importe>
</entry>
<entry>
<ID>01370BEFB56000A9C1257275004ECD78</ID>

<cliente>1062364</cliente>
<cif>68654716K</cif>
<numAlbaran>26H89648116</numAlbaran>
<numFactura>78J66958362</numFactura>
<fecha></fecha>
<importe>376021</importe>
</entry>
<entry>
<ID>018DC7067EFE824EC1257275004ECF39</ID>
<cliente>1062364</cliente>

<cif>68654716K</cif>
<numAlbaran>24H74748880</numAlbaran>
<numFactura>27J50652188</numFactura>
<fecha></fecha>
<importe>449938</importe>
</entry>
<entry>
<ID>01B36E87437566A0C1257275004ECCD0</ID>
<cliente>222233333</cliente>
<cif>68654716K</cif>

<numAlbaran>27H71715850</numAlbaran>
<numFactura>6J27910993</numFactura>
<fecha></fecha>
<importe>435707</importe>
</entry>
<entry>
<ID>01E628A782BD78EEC1257275004ECD5F</ID>
<cliente>1062364</cliente>
<cif>68654716K</cif>
<numAlbaran>33H39663216</numAlbaran>

<numFactura>43J51439679</numFactura>
<fecha>13%2F12%2F2006</fecha>
<importe>826331</importe>
</entry>
<entry>
<ID>024D67DCBBE8F0DFC1257275004ECF7D</ID>
<cliente>10623d64545454</cliente>
<cif>68654716K</cif>
<numAlbaran>11H24553195</numAlbaran>
<numFactura>66J75239086</numFactura>

<fecha></fecha>
<importe>818450</importe>
</entry>
<entry>
<ID>028A3F13B2B41895C1257275004ECE73</ID>
<cliente>15</cliente>
<cif>68654716K</cif>
<numAlbaran>27H37277272</numAlbaran>
<numFactura>21J65466309</numFactura>
<fecha></fecha>
<importe>880740</importe>

</entry>
<entry>
<ID>02985DEBB432432AC1257275004ECDCE</ID>
<cliente>1062364</cliente>
<cif>68654716K</cif>
<numAlbaran>86H67531973</numAlbaran>
<numFactura>86J43700179</numFactura>
<fecha>13%2F12%2F2006</fecha>
<importe>253674</importe>
</entry>

<entry>
<ID>02E4F3C151E3FFCDC1257275004ECCD2</ID>
<cliente>1062364</cliente>
<cif>68654716K</cif>
<numAlbaran>31H63877439</numAlbaran>
<numFactura>32J93980759</numFactura>
<fecha>13%2F12%2F2006</fecha>
<importe>554224</importe>
</entry>
<totalDocs>773</totalDocs>

</catalog>

The errors:

FireFox:

Error: unterminated regular expression literal
Línea: 14, columna: 12
Código fuente:
<cliente>11</cliente>

IE6:

Línea: 1
Error: Error de sintaxis



Any ideas?

carusombira
24 May 2007, 1:04 PM
Hi, I noticed that your code uses 'totalProperty' and not 'totalRecords' in the XmlReader settings. I had a problem with my paging grid when I didn't use 'totalRecords'
reader: new Ext.data.XmlReader({
record: 'Item',
totalRecords: 'results',
id: 'ASIN'
}, [
'ciid', $this->assDisplayColsList
])
});