andreacammarata
14 Jul 2009, 4:43 AM
Hi all,
I'm trying to write down a simple piece of code to learn how to use a Ext.data.DirectStore, but I don't figure out what's going on.
I explain better my problem:
What i want to do is really simple, i want to populate a GridPanel using a directFn.
I wrote and included in my test page a .ashx that returns me the remoting api as follow
Ext.app.REMOTING_API = {"type":"remoting","url":"/TestHandler.ashx","namespace":"MyApp","actions":{"Test":[{"name":"getAll","len":0}]}};
and after that i wrote down the source code of my test page
var store = new Ext.data.DirectStore({
storeId: 'fileStore',
autoLoad: true,
directFn: MyApp.Test.getAll,
paramsAsHash: false,
totalProperty: 'count',
root: 'testData',
fields: [
{name:'name', type: 'string'}
],
listeners: {
dataChanged: function(store){
Ext.Msg.alert('Store Load','The Data has been loaded!');
}}
});
var gp = new Ext.grid.GridPanel({
id: 'gp',
store: store,
renderTo: Ext.getBody(),
height: 300,
columns: [
{id: 'name', header: 'Name', sortable: true, dataIndex: 'name'}
],
sm: new Ext.grid.RowSelectionModel({
})
});
});
Now inspecting the execution with FireBug, I see the following response coming form the TestHandler.ashx
{"type":"rpc","tid":2,"action":"Test","method":"getAll","result":"{count:11,'testData':[{\"name\":\"kids_hug.jpg\"},{\"name\":\"kids_hug2.jpg\"},{\"name\":\"sara_pink.jpg\"},{\"name\":\"sara_pumpkin.jpg\"},{\"name\":\"sara_smile.jpg\"},{\"name\":\"up_to_something.jpg\"},{\"name\":\"zack.jpg\"},{\"name\":\"zacks_grill.jpg\"},{\"name\":\"zack_dress.jpg\"},{\"name\":\"zack_hat.jpg\"},{\"name\":\"zack_sink.jpg\"}]}","message":null}
This is Ok beacuse it means that the DirectHandler is called correctly and i'ma ble to retrive the data I need, but the problem is that the grid doesn't populate at all.
Note: If i change the DirectStore root property as follow
root: ''
the grid will be populated with a LOT of empty records and the 'Name' column doesn't contain any value.
Does anyone knows what i'm missing?
I read a lot of post and everyone solved with the config
paramsAsHash: false
but it doesn't seems to be my case.
Thanks a lot!
I'm trying to write down a simple piece of code to learn how to use a Ext.data.DirectStore, but I don't figure out what's going on.
I explain better my problem:
What i want to do is really simple, i want to populate a GridPanel using a directFn.
I wrote and included in my test page a .ashx that returns me the remoting api as follow
Ext.app.REMOTING_API = {"type":"remoting","url":"/TestHandler.ashx","namespace":"MyApp","actions":{"Test":[{"name":"getAll","len":0}]}};
and after that i wrote down the source code of my test page
var store = new Ext.data.DirectStore({
storeId: 'fileStore',
autoLoad: true,
directFn: MyApp.Test.getAll,
paramsAsHash: false,
totalProperty: 'count',
root: 'testData',
fields: [
{name:'name', type: 'string'}
],
listeners: {
dataChanged: function(store){
Ext.Msg.alert('Store Load','The Data has been loaded!');
}}
});
var gp = new Ext.grid.GridPanel({
id: 'gp',
store: store,
renderTo: Ext.getBody(),
height: 300,
columns: [
{id: 'name', header: 'Name', sortable: true, dataIndex: 'name'}
],
sm: new Ext.grid.RowSelectionModel({
})
});
});
Now inspecting the execution with FireBug, I see the following response coming form the TestHandler.ashx
{"type":"rpc","tid":2,"action":"Test","method":"getAll","result":"{count:11,'testData':[{\"name\":\"kids_hug.jpg\"},{\"name\":\"kids_hug2.jpg\"},{\"name\":\"sara_pink.jpg\"},{\"name\":\"sara_pumpkin.jpg\"},{\"name\":\"sara_smile.jpg\"},{\"name\":\"up_to_something.jpg\"},{\"name\":\"zack.jpg\"},{\"name\":\"zacks_grill.jpg\"},{\"name\":\"zack_dress.jpg\"},{\"name\":\"zack_hat.jpg\"},{\"name\":\"zack_sink.jpg\"}]}","message":null}
This is Ok beacuse it means that the DirectHandler is called correctly and i'ma ble to retrive the data I need, but the problem is that the grid doesn't populate at all.
Note: If i change the DirectStore root property as follow
root: ''
the grid will be populated with a LOT of empty records and the 'Name' column doesn't contain any value.
Does anyone knows what i'm missing?
I read a lot of post and everyone solved with the config
paramsAsHash: false
but it doesn't seems to be my case.
Thanks a lot!