PDA

View Full Version : GridPanel (extend) with XmlReader



alexol
24 Jan 2011, 12:40 PM
Someone tell me, I've created extend GridPanel and use XmlReader for loading data in it.

But cache of store is empty every time and grid empty too.

At the same time if use simple ArrayReader, all work and grid filed.

Who can help me?



Ext.onReady(function(){

Ext.QuickTips.init();

ListGrid = Ext.extend(Ext.grid.GridPanel, {
id: 'ListGrid',
width: '100%',
loadMask: true,
remoteSort: true,
border: false,
trackMouseOver:true,
renderTo: 'example-grid',

initComponent: function() {
var obj = this;

var _store = new Ext.data.Store({
url: 'sheldon1.xml',
reader: new Ext.data.XmlReader({
record: 'topic',
totalRecords: 'totalCount',
id: 'id'
}, [
{name: 'id', mapping: 'id', type: 'int'},
{name: 'topic', mapping: 'topic', type: 'string'},
{name: 'annotation', mapping: 'annotation', type: 'string'},
{name: 'show', mapping: 'show', type: 'int'},
{name: 'pubDate', mapping: 'pubDate', type: 'date', dateFormat:'timestamp'}
]),
autoLoad: false,
sortInfo: { field: 'pubDate', direction: 'DESC' },
remoteSort: true,

listeners: {
'datachanged' : function(o) {
alert(o.getTotalCount());
}
}

});

var _cm = new Ext.grid.ColumnModel([
{
header: "Title",
name: 'topic',
width: 400,
resizable: true,
sortable: false,
dataIndex: 'topic'
},

{
header: "Date",
name: 'pubDate',
width: 115,
sortable: true,
resizable: true,
dataIndex: 'pubDate'
}
]);

var _tbar = new Ext.Toolbar({
items: [
{
text: 'Add'
}
]
});

var _bbar = new Ext.PagingToolbar({
pageSize: 25,
store: _store,
displayInfo: true
});

var _viewConfig = {
forceFit:true
};

var config = {
store: _store,
cm: _cm,
viewConfig: _viewConfig,
tbar: _tbar,
bbar: _bbar
};

Ext.apply(this, Ext.apply(this.initialConfig, config));
ListGrid.superclass.initComponent.apply(this, arguments);
},
onRender: function() {
this.store.load({
params:{
start:0,
limit:20
}
});
ListGrid.superclass.onRender.apply(this, arguments);
}
});

new ListGrid();
});


XML:


<?xml version="1.0" encoding="utf-8"?>
<data>
<topics>
<topic>
<id>1</id>
<topic>Title 1</topic>
<annotation>Some Text</annotation>
<show>1</show>
<pubDate>1295719227</pubDate>
</topic>
<topic>
<id>2</id>
<topic>Title 2</topic>
<annotation>Some text</annotation>
<show>1</show>
<pubDate>1295719227</pubDate>
</topic>
</topics>
<totalCount>2</totalCount>
</data>