I'm reading about igGrid remote paging here : http://help.infragistics.com/NetAdvantage/jQuery/2013.1/CLR4.0?page=igGrid_Paging.html.
However, it's still unclear to me how I setup my remote paging if I'm NOT using the IG wrappers.
Could someone advise me on how to use recordCountKey and responseDataKey to configure this ? How do I implement my c# page method on the server-side, is it through the grid's "pageIndexChanging" event ?
As per the link above, it says :
"If you are implementing your own remote service (for example in ASP.NET or PHP), in order to properly initialize and render the pager, your service must specify both the responseDataKey (grid option) and the recordCountKey (paging option). The recordCountKey member tells the Paging widget how many records in total are in the backend. The responseDataKey specifies which property in the response contains the resulting data.
Therefore, when remote paging is used, the grid automatically generates the proper request parameters in the following way:
http:///grid/PagingGetData?page=2&pageSize=25"
ex/
$("#imGrid").igGrid({ //dataSource: jsonData,
dataSource: "/Margins/getTrades?level=account&entityName=" + entityName, responseDataKey: "Data.data", columns: [ { headerText: "Member", key: "entityName", dataType: "string", width: "100px" }, { headerText: "Margin", key: "Margin", dataType: "number", format: "double", width: "120px" }, ], features: [ name: "Paging", type: "remote", pageSize: 10,
recordCountKey: "Data.recordCountKey", }
});
and my controller code returns a nice-formatted Json object :
public dynamic getTrades(string entityName, string level = "member") { // Bind to Service (details omitted) BasicHttpBinding httpBinding = new BasicHttpBinding(); // Converts List type to Json format below JavaScriptSerializer ser = new JavaScriptSerializer(); var tradeData = myService.GetTrades(entityName); var jsonDataObj = Json(new { recordCountKey = 50, responseDataKey = "data", data = tradeData }); string jsonData = ser.Serialize(jsonDataObj); return jsonData; }
Hey Bob,
recordCountKey is a property you need to add to the response data which specifies the total number of records (so that the grid UI knows what to show and how to calculate, i.e. XXX of YYY records, where YYY is the total number of records). responseDataKey is a property holding your array of actual data records. As I see from your example above, those are already properly set. Do you need to add "Data" in front of ".data" and ".recordCountKey", respectively. Could you show me some example response JSON that you're sending to the browser?
As for the pageSize and page index ("page") parameters, you need to add extra parameters to your service method and read them in its implementation, so that you know which page the client requests. so you need to do something like this :
var tradeData = myService.GetTrades(entityName, pageSize, pageIndex); // where pageSize and page are parameters that the service will read from the URL, similar to entityName.
Then you need to modify your GetTrades method to take into account this pageSize and page (the index), in order to return the correct data portion.
Hope it helps. Thanks,
Angel
Hi Angel,
Yes in fact I do need to qualify responseDataKey with "Data.data". The reason is when the following controller code returns jsonData,
var tradeData = myService.GetTrades(entityName); var jsonDataObj = Json(new { recordCountKey = tradeData.Count(), responseDataKey = "data", data = tradeData }); string jsonData = ser.Serialize(jsonDataObj); return jsonData;
jsonData is then returned back to the client with the property "Data" as the top level of jsonData. Take a look at my debug screen shot :
{"ContentEncoding":null,"ContentType":null,"Data":{"recordCountKey":37,"responseDataKey":"data","data":[{"ExtensionData":{},"Account":"0012F","BuySell":0,"FaceValue":0,"Member":"3D","SettlementDate":"\/Date(1421298000000)\/","TradeDate":"\/Date(1358226000000)\/","TradeID":null,"contractID":"CGZU12","qty":3,"source":"IX"},{"ExtensionData":{},"Account":"0012F","BuySell":0,"FaceValue":0,"Member":"3D","SettlementDate":"\/Date(1421384400000)\/","TradeDate":"\/Date(1358312400000)\/","TradeID":null,"contractID":"CGZZ12","qty":13,"source":"IX"},{"ExtensionData":{},"Account":"0012F","BuySell":0,"FaceValue":0,"Member":"3D","SettlementDate":"\/Date(1421470800000)\/","TradeDate":"\/Date(1358398800000)\/","TradeID":null,"contractID":"CGZH13","qty":1,"source":"IX"},{"ExtensionData":{},"Account":"0012F","BuySell":0,"FaceValue":0,"Member":"3D","SettlementDate":"\/Date(1421557200000)\/","TradeDate":"\/Date(1358485200000)\/","TradeID":null,"contractID":"CGZM13","qty":69,"source":"IX"}}
hey Bob,
it should be just "page" not "pageIndex" (this is the default name). Could you let me know if those are sent as part of the request? You can use Firebug or Dev tools for IE to track the request/response.
Thanks
Actually, yes. I can see the see the additional params getting appended when I use IE F12 tool.
Here's the Request Header:
Key ValueRequest GET /Margins/getTrades?level=account&entityName=0012F&%24skip=0&%24top=25&%24inlinecount=allpages&pk=tradeId&_=1373992748886 HTTP/1.1
So it appears I need different parameter names...
thx
Bob
Ok, i see. yep those are the default ones, that's the default naming in the OData spec. If you need them to be pageIndex or pageSize, you can set it like this:
features: [
{
name: "Paging",
pageIndexUrlKey: "pageIndex",
pageSizeUrlKey: "pageSize"
}
]
Thanks,
oh, and I didn't even have oData set to true. But i suppose that's the oData default as you mentioned, even if not explicitly set to true.
Using std oData, I can't access the parameters in my controller (so I'll stick to your idea re: changing the index keys) :
public dynamic getTrades(string entityName, string level = "member", int skip = 1, int top = 10, string inlinecount="allpages", string pk="tradeId")
....
GOOD NEWS: So now that I've change pageIndexUrlKey and pageSizeUrlKey, I can clearly see the params to passed into my c# controller.
Key ValueRequest GET /Margins/getTrades?level=account&entityName=0012F&pageIndex=3&pageSize=10&pk=tradeId&_=1373999367405 HTTP/1.1
It's gonna be a bit complicated on the server and/or service side, but not impossible.
As you said, if I know the Total Rec Count, the current Page Index, and the Page Size - then my custom logic should be able to extract the appropriate records from the service.
Does that sound correct from a general perspective ?
thanks.
yes this sounds perfect, and that's how I think you should do it as a best practice, assuming you aren't relying on our MVC wrappers. By the way, I think it is worth trying with the MVC wrappers, I am sure you will be surprised by how much work they do for you : ) I mean, paging, sorting, filtering, and you don't need to bind to a specific data source type - it's just IQueryable, so you can even pass a list of objects and all those operations I mentioned - paging/sorting/filtering/ etc. - will work out of the box, in any combination.
Let me know how it goes. Thanks,
Hello,
In my opinion your scenario is related to https://github.com/IgniteUI/igniteui-angular2/issues/146
Follow the issue to receive notification, we will resolve it soon and your scenario should be covered too.
We are following the same above steps to use remote paging in Ig tree grid. below are our codesnippet, we are getting error like arrays and iterates are only allowed when we give URl in dataSource. Please help us on this.
<ig-tree-grid [options]='gridOptions' [widgetId]='id'></ig-tree-grid>
this.gridOptions = { responseDataKey: "Data.Records", dataSource: "/api/DealsList?UserID=" + this.userID, height: "500", width: "100%", columns: [ ---------- ], features: [ { name: "Paging", type: "remote", pageSize: 20, recordCountKey: "Data.recordCountKey", pageIndexUrlKey: "pageIndex", pageSizeUrlKey: "pageSize" } ] };
Json I'm getting from API:
{"ContentEncoding":null,"ContentType":null,"Data":{"Records":"[{\"DealId\":47r3254545456,\"Phase\":541,\"DealName\":\"StatusChangeTest\",\"StatusId\":22457,\"StatusName\":\"Re-Authorization Approval Pending\"}]","recordCountKey":3634,"responseDataKey":"Records"},"JsonRequestBehavior":0,"MaxJsonLength":null,"RecursionLimit":null}
error while i'm running :
ERROR Error: Error trying to diff '/api/DealsList?UserID=X202942'. Only arrays and iterables are allowed
ERROR CONTEXT [object Object]
Do we missing some thing on this setting for remote paging.
Hi Alexander.
I would like to know about if with remote paging can I still using this kind of filters on the grid.
Currently, before team developer than mine, were sending all data to the client and doing paging, sorting and filtering all sucessfully but when end workdays at office, IIS (Internet Information) died because there were so much clients connected and getting around 3 thousands register in this way.
I am planning change for remote paging, but I am wondering about these filters since they are so useful for our users.
Thanks in advance. Here in the company we got IG licensed btw.
Great to hear, thanks Bob.
Thanks Angel. And yes, we've been already playing with virtualization - and we like it very much.
We just have to be careful that eventually the returned dataset doesn't get into the 10s of thousands...
thank you.