PDA

View Full Version : Grouping in grid with Ext.data.XmlStore



luke82
23 Nov 2010, 10:19 AM
Hello,
I am looking for a solution for grouping in grid with XML data loaded.

My store at this moment:


Store_Xml = Ext.extend(Ext.data.XmlStore, {
constructor: function(cfg) {
cfg = cfg || {};
Store_Xml.superclass.constructor.call(this, Ext.apply({
storeId: 'storeXml',
url: my.xml',
record: 'Items',
fields: ['id', 'name', 'group'],
autoLoad: true,
remoteSort: false,
totalRecords: '@total',
sortDir: 'ASC',
autoSave: false,
groupField:'group'
}, cfg));
}
});


All working fine, just grouping. Thank you for any help.

Condor
24 Nov 2010, 2:18 AM
Create a GroupingStore with an XmlReader.

luke82
24 Nov 2010, 2:37 AM
Thank you for reply Condor. Yes I tried find a solution... But when I change


...
Ext.extend(Ext.data.XmlStore, {
...


to



...
Ext.extend(Ext.data.GroupingStore, {
...

FireBug get me a result with XML (same as from XmlStore), but Grid displayed nothing.

Do you have some example for this? When I have UI file and store file separately... THX

Condor
24 Nov 2010, 2:42 AM
That's not the only change you need to make! You also need to configure a reader (XmlReader instance) in the GroupingStore.

luke82
24 Nov 2010, 3:54 AM
Thanks Condor. Now it works.

Solution:


Store_Xml = Ext.extend(Ext.data.GroupingStore, {
constructor: function(cfg) {
cfg = cfg || {};
Store_Xml.superclass.constructor.call(this, Ext.apply({
storeId: 'storeXml',
url: my.xml',
autoLoad: true,
totalRecords: '@total',
sortDir: 'ASC',
autoSave: false,
reader: new Ext.data.XmlReader({
record: 'Items',
fields: ['id', 'name', 'group'],
remoteSort: false
}),
groupField:'group'
}, cfg));
}
});


and next I had to edit UI file. Insert there:



view: new Ext.grid.GroupingView({
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
}),


THX

Condor
24 Nov 2010, 3:59 AM
- totalRecords is an XmlReader config option
- remoteSort is a Store config option