How to call a .NET Jayrock RPC via a Ext.Store Proxy to paginate the response data?
Hey,
I'm trying to use the proxy in my Ext.data.Store to request data from a remote procedure (RP). I'm doing this, because I want to use pagination in a grid panel. I tried it without pagination, the .NET Jayrock Framework provides an auto-generated JavaScript file that contains a small object with all existing functions on the server-side. So you can use these functions to make an ajax call to all RP functions. The response is handled by an individual defined (ajax callback) function. In this callback I'm using the Ext.data.Store.add() method to add every record manually. This is nice and works fine, but it seems to me that there's a big problem by using this with pagination.
By now I can fill all the (JSON) response from the RP to my Ext.grid.Panel. Fine!
But now I want to use the cool Ext.toolbar.Paging feature for that grid. I tried to do a RPC via an ajax Proxy in the Ext.data.Store - 'cause of the REST behaviour I've overwritten the 'actionMethods:' to use POST instead of GET and I used the 'extraParameters:' to configure the same structure as of the POST request over the Jayrock auto-generated methods.
For this I just analyzed the XMLHttpRequest behaviour of the Jayrock generated JavaScript file. The header looks something like:
Code:
| Host |
localhost |
| User-Agent |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1 |
| Accept |
text/plain, */* |
| Accept-Language |
de-de,de;q=0.8,en-us;q=0.5,en;q=0.3 |
| Accept-Encoding |
gzip, deflate |
| Accept-Charset |
ISO-8859-1,utf-8;q=0.7,*;q=0.7 |
| Connection |
keep-alive |
| Content-Type |
text/plain; charset=utf-8 |
| X-Requested-With |
XMLHttpRequest |
| X-JSON-RPC |
rpcMethodToLoadOnServer |
| Content-Length |
130 |
with a JSON Object sent:
{"id":0,"method":"rpcMethodToLoadOnServer","params":[...(SOME PARAMS)...]}
After my stores editing to:
Code:
Ext.define('MyProject.store.Datas', {
extend: 'Ext.data.Store',
model: 'MyProject.model.Data',
autoLoad: false,
pageSize: 5,
proxy: {
type: 'ajax',
url: '/pathonmyserver/rpchandler.ashx',
actionMethods: {
read : 'POST' // used for simulating the POST for RPC call
},
reader: {
type: 'json',
totalProperty: 'total'
}
}
});
I'm getting
Code:
| Host |
localhost |
| User-Agent |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1 |
| Accept |
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 |
| Accept-Language |
de-de,de;q=0.8,en-us;q=0.5,en;q=0.3 |
| Accept-Encoding |
gzip, deflate |
| Accept-Charset |
ISO-8859-1,utf-8;q=0.7,*;q=0.7 |
| Connection |
keep-alive |
| Content-Type |
application/x-www-form-urlencoded; charset=UTF-8 |
| X-Requested-With |
XMLHttpRequest |
| Content-Length |
141 |
with no JSON object sent (because I've no solution how to solve this). I've just used extraParams - but this will add all the parameters only and not in JSON format. And there's no X-JSON-RPC set!
This results in an "application/x-www-form-urlencoded" Content-Type header instead of the correct "text/plain".
1. How can I solve this? Is there a comfortable way in Ext?
2. I also want to send a JSON object with that request, how can I do this?
Many thanks in advance!