Ok i change server side code to
int nm = objects.ToList().Count;
if (objects.ToList().Count > 0)
return new PagedList(objects, nm, 1, 25, null);
else return null;
json is change to
{"d":{"total":15,"page":1,"records":366,"rows":[{"id":"34324","LastDateChange":"/Date(1391464800000)/","DateLoad":"/Date(1391464800000)/"....,"AName":"fg"}],"userData":null}}
client side
$("#table").jqGrid({
url: '/WebSrv.asmx/GetSaleObjects',
datatype: 'json',
mtype: 'POST',
loadonce: true,
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: function (postData) {
},
viewrecords: true,
sortable: true,
gridview: true,
multisort: true,
height: 'auto',
width: 'auto',
pager: "#pgrf",
autowidth: true,
pagination: true,
jsonReader: {
root: "d.rows",
page: "d.page",
total: "d.total",
records: "d.records"
}
....
});
but grid is empty! don`t uderstand ;( , may be sample ?
It seems that you get very very old example as the template for your solution. The option imgpath
for example is deprecated (see the documentation ) already in version 3.5. So you used template created for at leas 5 yeas old version of jqGrid.
Another important bug in your code is the usage of manual JSON serialization inside of ASMX web service method. You should remove call of Newtonsoft.Json.JsonConvert.SerializeObject
from the GetSaleObjects
. The method should return PagedList
object or just Object
. By the way you can return objects
(or objects.ToList()
) instead of new PagedList(objects, objects.ToList().Count, 1, objects.ToList().Count)
in case of usage loadonce: true
because jqGrid ignores page
, records
and total
parts of the server response in case of loadonce: true
.
It's important to understand that current code serializes the results to JSON twice . So you have to call JSON.parse
inside of success
handle of $.ajax
. For example if you have an new PagedList(...)
object then the firs serialization to JSON produce the string like
{"total":1,"page":1,"records":350,"rows":[...]}
ASP.NET serialize additionally the returned results. So one modify the returned value to the string
"{\"total\":1,\"page\":1,\"records\":350,\"rows\":[...]}"
Deserialization of correct JSON string ( {"total":1,"page":1,"records":350,"rows":[...]}
) will produce the object with properties total
, rows
etc. on the client side . On the other side deserialization of the wrong string ( {\\"total\\":1,\\"page\\":1,\\"records\\":350,\\"rows\\":[...]}
) produce the string which contains the text {"total":1,"page":1,"records":350,"rows":[...]}
. Only if one apply additional call of jQuery.parseJSON
or JSON.parse
one will get required object .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.