PDA

View Full Version : Updating store/grid with loadData



johnr
13 Jun 2007, 6:33 AM
Hello everyone,

I've been wrestling with this issue for some time now, but still can't seem to figure it out.

Here's what I'm trying to do: First I grab a bunch of data off of testdata.xml and push it into my grid. That works fine, but later on, I'd like to have the user hit a button to append additional data into my grid from a separate xml file (testdata2.xml). I'm trying to get loadData to grab the new data from the new xml file for me, but I can't seem to get it to work properly.


function Table() {
this.account = Ext.data.Record.create([
{name: 'Selected', type: 'string'},
{name: 'Eri', type: 'string'},
{name: 'AcctNum', type: 'string'},
{name: 'AcctName', type: 'string'},
{name: 'Value', type: 'float'}
]);

this.ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: 'testdata.xml'}),
reader: new Ext.data.XmlReader({record: 'Item', id: 'AID'}, this.account)
});
this.ds.load();

// ...grid business
}


function addAccount() {
lt.ds.loadData(/*pass in testdata2.xml data*/, true);
}

Ext.onReady(
function() {
lt = new Table();
}
);

I'm pretty sure I'm just not sending the data object into loadData() in the correct format... I've looked all over the forums but can't seem fix this. Any help would be much appreciated!

sjivan
13 Jun 2007, 6:47 AM
You might have to issue an ajax call for the xml file and in callback read the response xml and then pass it to loadData()

function addAccount() {
Ext.Ajax.request({url: 'testdata2.xml', callback: myCallback});
}

johnr
13 Jun 2007, 9:26 AM
Thanks for the quick reply. I've managed to make some progress using load() instead of loadData(), but when I attempt to include parameters in my load statement, things appear to stop working. Does anyone know why that might be? Thanks again for the help!


function addAccount() {
lt.ds.proxy.getConnection().url = 'http://testHost/testServlet';

// this works
lt.ds.load();

// this doesn't work
// lt.ds.load({add:true});

// this doesn't work either
tt.ds.load({params: {num: 123456}});
}

tryanDLS
13 Jun 2007, 9:33 AM
What doesn't work? Why does that last line say 'tt' instead of 'lt'? Step thru the store.load fn in firebug to see what happens with the args you pass to load.