PDA

View Full Version : Can't get store and XMLReader to work



elbino
8 Jul 2013, 1:45 AM
Hello there,

I am trying to access a store with the help of an xml reader. Unfortunately this does not work. I tried to do this like the Sencha ExtJS examples but something must be wrong here.

My store:


var store = new Ext.data.Store({


autoLoad:true,
url: 'servlet/TaskHelperLoadHistory',


reader: new Ext.data.XmlReader({


root:'Items',
totalRecords:'@total',
record: 'Item',
id: 'Version'
}, [
// set up the fields mapping into the xml doc
'Version', 'Editor', 'Comment'
])
});


In my grid I try to use the store:


...
xtype:"panel",
title:"History",
items:[{
xtype:"fieldset",
style:"margin:10px",
title:"History",
store:store,
height:300,
items:[{
xtype:"grid",
columns:[
{header:"Version", dataIndex: 'Version'},
{header:"Editor", dataIndex: 'Editor'},
{header:"Comment", dataIndex: 'Comment'}
]
}]
}]
...


When debugging with firebug the store seems to be empty. What can be wrong? Ah, here is my XML document:


<Items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" total="5">
<Item>
<Version>1</Version>
<Editor>James</Editor>
<Comment>test</Comment>
</Item>
<Item>
<Version>2</Version>
<Editor>John</Editor>
<Comment>bla bla</Comment>
</Item>
</Items>

Pretty simple ... But I can't get this working.

Thanks & best regards
Thomas

slemmon
8 Jul 2013, 10:24 PM
Your store needs a fields array to tell it how to store the parsed XML data. See the example at the top of the XmlStore API doc:
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.XmlStore

When you set up your grid it will need both a columns config and a store config. Your sample code is missing the store config from the grid. See the example at the top of the grid panel's API docs page for reference:
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.grid.Panel

elbino
10 Jul 2013, 4:10 AM
Thanks for your help. :) I already discovered my mistake yesterday. I assigned my store to the fieldset but not to the grid. After changing this it worked.