I recommend you to use standard datatype: 'json'
instead of datatype
as function. You need only use additionally
datatype: 'json',
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
mtype: 'GET',
(see Setting the content-type of requests performed by jQuery jqGrid for example)
and return jqGridTable class instance defined like following
public class jqGridTable
{
public int total { get; set; } // total number of pages
public int page { get; set; } // current zero based page number
public int records { get; set; } // total number of records
public List<jqGridRow> rows { get; set; }
}
public class jqGridRow
{
public string id { get; set; }
public List<string> cell { get; set; }
}
Or if we want use the most compact form of data transferred from server to client then following
// jsonReader: { repeatitems : true, cell:"", id: "0" }
public class jqGridTable {
public int total { get; set; } // total number of pages
public int page { get; set; } // current zero based page number
public int records { get; set; } // total number of records
public List<List<string>> rows { get; set; }// first element of row must be id
}
Probably you should use a little other jsonReader
to be able to decode data from the d
property of the web service results (see Jqgrid 3.7 does not show rows in internet explorer).
To support server side paging and sorting you should add
int page, int rows, string sidx, string sord
to the list of parameters of your service.
UPDATED: Other link jqgrid Page 1 of x pager has practically full code of both jqGrid and the ASMX service. You can use the following simple jsonReader
:
jsonReader: { root: "d.rows", page: "d.page", total: "d.total",
records: "d.records", id: "d.names" }