1

My problem lies with jQGrid and an OData data source (.NET WCF)

I am attempting to get jQgrid paging to work correctly, currently I have a basic data load and column sorting functioning.

I did this by overriding the xmlReader function to get jQgrid to parse the OData XML

xmlReader: {
    root: "feed",
    row: "entry",
    id: "entry>id",
    total: "m:count"
}

Then on the request to the server I overrode the serializeGridData function to attempt to send the requst in OData format.

serializeGridData: function (obj) {
    obj["$inlinecount"] = "allpages";
    obj["$orderby"] = obj.sidx + " " + obj.sord;
    obj["$skip"] = (obj.page - 1) * obj.rows;
    return obj;
}

But the problem is the OData response only contains the m:count which is the total number of records. I believe jQGrid needs at least totalrecords, currentpagenum, and totalPages to get the pagination to work correctly.

What am I missing?

A side question is how does Kendo UI Grid accomplish this and is there anything I can learn (or lift) from their code??

Server Side Paging Demo - http://demos.kendoui.com/web/grid/remote-data.html

Where the demo communicates with an oData source: http://demos.kendoui.com/service/Northwind.svc/Orders

Using the same oData format and getting the same response - lacking page number.

Ton van den Heuvel
  • 10,157
  • 6
  • 43
  • 82
twozero
  • 11
  • 2

2 Answers2

2

If you'd like... I've gotten it working for a project I'm on, and I have a gist up that you can peruse...

https://gist.github.com/dealproc/6678280

Richard B
  • 1,581
  • 1
  • 15
  • 31
1

First of all I recommend you to use JSON instead of XML to communicate with OData WCF service. If you use ASP.NET 4.X then you will need just include automaticFormatSelectionEnabled="true" attribute in settings of the endpoint of WCF service. See the answer for more details. After that you can just use datatype: "json" and ajaxGridOptions: { contentType: "application/json" } options of jqGrid. The OData WCF service will returns JSON data.

The example of serializeGridData, jsonReader and prmNames you will the answer. I think that you can just use the options in your case too.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798