PDA

View Full Version : PagingXmlStore changing XML source runtime



vtulin
10 Jun 2010, 10:13 PM
I'm using a store locally, and to have a greater performance, I'm filtering data using XPath, it's much more simplier and faster. When I'm using my store without paging I'm just changing my proxy, and load data again:


grid.store.proxy = new Ext.data.MemoryProxy(xml);
grid.store.load();

all works fine, but when I'm using a paging store, the same method works, but it breaks paging, and if I'm doing the following:


grid.store.proxy = new Ext.data.MemoryProxy(xml);
grid.store.load({ params: { start: 0, limit: 15} });

it does nothing, the source is not changing.

What should I do to reload an XML to my paging store?

Thank you.

Condor
10 Jun 2010, 10:53 PM
Already answered in the PagingStore thread.

You can't change the proxy of a store!!! (you can, but it involves a lot more code than you think).

vtulin
10 Jun 2010, 11:01 PM
Let's discuss it here.
So still nothing, I still got the same data in my grid...
Maybe something wrong with lastOptions? What is it purpose? When I'm removing this property from store all work absolutely the same.

Condor
11 Jun 2010, 12:10 AM
PagingStore checks if lastOptions exists to see if it need to request new data or use the already loaded data. Removing lastOptions will make PagingStore request new data from the proxy.

What have you debugged so far? Is the proxy actually being called to request the data (load event)?

vtulin
11 Jun 2010, 3:29 AM
"load" event is calling on changing proxy data, I've checked. What else can I check?

vtulin
11 Jun 2010, 3:56 AM
Maybe grid.getStore().proxy.data must have some specific format? I'm trying to put IXMLDomDocument there...

Condor
11 Jun 2010, 5:23 AM
It depends on what your reader does with it. Can XMLReader handle an IXMLDomDocument (haven't checked)?

vtulin
11 Jun 2010, 5:28 AM
It depends on what your reader does with it. Can XMLReader handle an IXMLDomDocument (haven't checked)?
Actually I don't use XMLReader in it's natural view, I'm using an XmlStore (now it's PagingXmlStore). XmlStore eats IXMLDomDocument. As I wrote previously if I just change proxy and launch load function the source is changing, but load function without parameters breaks paging...

Condor
11 Jun 2010, 5:44 AM
An XMLStore is nothing more than a Store with a preconfigured XmlReader.

As I said, you can't change the proxy of a store. Instead, you should change the data of an existing MemoryProxy.

If the proxy load event is fired then PagingStore is actually requesting new data. Does the 'loadexception' event get fired (and with which arguments)?

vtulin
13 Jun 2010, 1:12 AM
No exceptions. Here I've created a simple example, to check:


Ext.onReady(function() {
var xml = new ActiveXObject("Msxml2.DOMDocument.4.0");
xml.async = false;
xml.loadXML("<root><item>100</item><item>200</item><item>300</item><item>400</item>\
<item>500</item><item>600</item><item>700</item><item>800</item><item>900</item>\
<item>1000</item><item>1100</item><item>1200</item><item>1300</item><item>1400</item></root>");
if (xml.readyState == 4 && xml.parseError.errorCode == 0) {
var grid = new Ext.grid.GridPanel({
store: new Ext.ux.data.PagingXmlStore({
lastOptions: { params: { start: 0, limit: 5} },
autoDestroy: true,
proxy: new Ext.data.MemoryProxy(xml),
record: "item",
fields: [{ name: "item", mapping: ""}]
}),
columns: [{ header: "Item", dataIndex: "item"}],
tbar: [],
bbar: []
});
var tbar = grid.getTopToolbar();
tbar.add(new Ext.Button({ text: "x2", listeners: {
click: function() {
var items = xml.selectNodes("//item");
Ext.each(items, function(item) {
item.text = parseFloat(item.text) * 2;
});
grid.getStore().proxy.data = xml; // assuming the proxy already is a MemoryProxy.
delete grid.getStore().lastOptions; // makes PagingStore request new data instead of returning page.
grid.getStore().load({ params: { start: 0, limit: 5} }); /**/
/* UNCOMMENT TO SEE HOW IT WORKS WITH PAGING BREAKING
grid.getStore().proxy = new Ext.data.MemoryProxy(xml);
grid.getStore().load();
/**/
}
}
}));
var bbar = grid.getBottomToolbar();
bbar.add(new Ext.PagingToolbar({ pageSize: 5, store: grid.store, displayInfo: true }));
grid.store.load({ params: { start: 0, limit: 5} });
var viewport = new Ext.Viewport({
renderTo: Ext.getBody(),
layout: "fit",
items: grid
}); /**/
}
});

Condor
13 Jun 2010, 5:50 AM
My fault, you have to delete lastParams and not lastOptions.

ps. Your example only works on IE. Wouldn't you rather use something more cross-browser compatible, e.g.

Ext.onReady(function () {
var xml, str = '<root><item>100</item><item>200</item><item>300</item><item>400</item><item>500</item><item>600</item><item>700</item><item>800</item><item>900</item><item>1000</item><item>1100</item><item>1200</item><item>1300</item><item>1400</item></root>';
if (window.ActiveXObject) {
xml = new ActiveXObject('Microsoft.XMLDOM');
xml.async = 'false';
xml.loadXML(xml);
} else {
xml = new DOMParser().parseFromString(str, 'text/xml');
}
var store = new Ext.ux.data.PagingXmlStore({
autoLoad: {
params: {
start: 0,
limit: 5
}
},
autoDestroy: true,
proxy: new Ext.data.MemoryProxy(xml),
record: 'item',
fields: [{
name: 'item',
mapping: '/'
}]
});
var tbar = [{
text: 'x2',
listeners: {
click: function () {
var items = Ext.DomQuery.select('item', xml);
Ext.each(items, function (item) {
if (item.textContent) {
item.textContent = parseFloat(item.textContent) * 2;
} else if (ci.innerText) {
item.innerText = parseFloat(item.innerText) * 2;
}
});
//grid.getStore().proxy.data = xml;
delete grid.getStore().lastParams;
grid.getStore().load({
params: {
start: 0,
limit: 5
}
});
}
}
}];
var bbar = new Ext.PagingToolbar({
pageSize: 5,
store: store,
displayInfo: true
});
var grid = new Ext.grid.GridPanel({
store: store,
columns: [{
header: 'Item',
dataIndex: 'item'
}],
tbar: tbar,
bbar: bbar
});
var viewport = new Ext.Viewport({
renderTo: Ext.getBody(),
layout: 'fit',
items: grid
});
});

vtulin
14 Jun 2010, 12:47 AM
Thanks! It works!