PDA

View Full Version : XML & Grid iusse



r2k
13 Aug 2007, 4:46 PM
Hi!, i'm having a little iusse with a grid in a form i'm getting a data from a XML file (made by me as example) to retrieve data and show it in the grid but something weird happens..

when the grid read a row show the data like you expect followed by a blank row ... i don't know why happens anyone can help me

XML Data


<?xml version="1.0" encoding="UTF-8"?>
<rows>
<total>2</total>
<data>
<id>1</id>
<nom>VAD</nom>
<pr>21</pr>
<dis>12.5</dis>
<fa>ABC</fa>
<ide>12</ide>
</data>
<data>
<id>2</id>
<nom>CNC</nom>
<pr>21</pr>
<dis>0</dis>
<fa>AB</fa>
<ide>15</ide>
</data>
</rows>


and the grid show like this



column 1 | column 2| column 3| column 4| column 5| column 6
---------+------------+------------+-----------+-----------+-----------
data | data | data | data | data | data
---------+------------+------------+-----------+-----------+-----------
| | | | |
---------+------------+------------+-----------+-----------+-----------
data | data | data | data | data | data
---------+------------+------------+-----------+-----------+-----------
| | | | |
---------+------------+------------+-----------+-----------+-----------


Fragment of Original Source Code


//-------------------- GRID -----------------------//
cm = new Ext.grid.ColumnModel([
{header: "Column 1", width: 20, sortable: false, dataIndex: 'id', locked: true},
{header: "Column 2", width: 70, sortable: false, dataIndex: 'nom', locked: true},
{header: "Column 3", width: 100, dataIndex: 'pr', sortable: false},
{header: "Column 4", width: 100, dataIndex: 'dis', sortable: false},
{header: "Column 5", width: 70, dataIndex: 'fa', sortable: false},
{header: "Column 6", width: 90, dataIndex: 'ide', sortable: false, resizable: false}
]);



var ds = new Ext.data.Store({
// load using HTTP
proxy: new Ext.data.HttpProxy({url: 'data.xml'}),
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
record: 'data',
id: 'id',
totalRecords: 'total'
}, // set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
['id','nom','pr','dis','fa','ide'])
});

grid = new Ext.grid.Grid(oTmp2, {
ds: ds,
cm: cm,
//selModel: mySelectionModel,
autoSizeColumns: true,
monitorWindowResize: false,
trackMouseOver: true
});

ds.load();
grid.render();

r2k
13 Aug 2007, 5:55 PM
solved ... i put two distinct markups whit the same name oops! hehehe

koffdsa
16 Aug 2007, 1:33 AM
i hava the same problem of use the grid to show the xml data,this is my code
XML:

<?xml version="1.0" encoding="utf-8"?>
<dataset>
<results>2</results>
<row>
<id>1</id>
<name>Bill</name>
<occupation>Gardener</name>
</row>
<row>
<id>2</id>
<name>Ben</name>
<occupation>Horticulturalist</name>
</row>
</dataset>

js:


Ext.onReady(function(){

// create the Data Store
var ds = new Ext.data.Store({
// load using HTTP
proxy: new Ext.data.HttpProxy({url: 'XMLGridStart.xml'}),

// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "row" tag
record: 'row',
id: 'id'
}, [
// set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
'name','occupation'
])
});

var cm = new Ext.grid.ColumnModel([
{header: "name", width: 120, dataIndex: 'name'},
{header: "occupation", width: 80, dataIndex: 'occupation'}
]);
cm.defaultSortable = true;

// create the grid
var grid = new Ext.grid.Grid('example-grid', {
ds: ds,
cm: cm
});
grid.render();
ds.load();
});

can you help me?thank you for you reply

koffdsa
16 Aug 2007, 8:06 PM
..solved,i make a fool mistake,i did't take my code to the server.