There are a misunderstanding. If you use datatype: local
then you have to fill jqGrid yourself with respect of methods like addRowData
or set the data in once with respect of data
parameter (for jqGrid version 3.7 and higher). So the usage of datatype: local
follows to jqGrid don't load any data itself and your datatype: processrequest
parameter will be ignored.
If you want to use loadonce: true
parameter which is supported since the version 3.7 of jqGrid, you should have all parameters of jqGrid for json or xml (for example datatype: json
in your case) and additional parameter loadonce: true
. Then after the first load of data jqGrid will switch the datatype to datatype: local
and after that it will work independent on server but ignore some parameters (like datatype: processrequest
in your case).
One more small remark. The most properties of jsonReader
which you use in your example are default (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data). The parameters which you use will be combined with the default properties, so it is enough to use parameter like
jsonReader: { repeatitems: false, id: "ID"}
UPDATED: OK Jeff. It seems to me, to solve your problem you need some more code examples from both sides: client and server. Here is a small example which I created and tested for you.
First of all the server side. In the ASMX web service we define a web method which generate a test data for your table:
public JqGridData TestMethod() {
int count = 200;
List<TableRow> gridRows = new List<TableRow> (count);
for (int i = 0; i < count; i++) {
gridRows.Add (new TableRow () {
id = i,
cell = new List<string> (2) {
string.Format("Name{0}", i),
string.Format("Title{0}", i)
}
});
}
return new JqGridData() {
total = 1,
page = 1,
records = gridRows.Count,
rows = gridRows
};
}
where classes JqGridData
and TableRow
are defined like following:
public class TableRow {
public int id { get; set; }
public List<string> cell { get; set; }
}
public class JqGridData {
public int total { get; set; }
public int page { get; set; }
public int records { get; set; }
public List<TableRow> rows { get; set; }
}
How you can see, the web method TestMethod
has no parameters and post back the full data. Paging, sorting and searching of data will do jqGrid (version 3.7 or higher).
To read such data and place there in the jqGrid we can do following:
$("#list").jqGrid({
url: './MyTestWS.asmx/TestMethod',
datatype: 'json',
mtype: 'POST',
loadonce: true,
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
jsonReader: {
root: function (obj) { return obj.d.rows; },
page: function (obj) { return obj.d.page; },
total: function (obj) { return obj.d.total; },
records: function (obj) { return obj.d.records; }
},
colModel: [
{ name: 'name', label: 'Name', width: 250 },
{ name: 'title', label: 'Title', width: 250 }
],
rowNum: 10,
rowList: [10, 20, 300],
sortname: 'name',
sortorder: "asc",
pager: "#pager",
viewrecords: true,
gridview: true,
rownumbers: true,
height: 250,
caption: 'My first grid'
}).jqGrid('navGrid', '#pager', {edit: false, add: false, del: false, search: true},
{},{},{},{multipleSearch : true});
Small comments about the definition of jqGrid.
To communicate with ASMX web service with respect of JSON one need do in the corresponding jQuery.ajax
request following
dataType: 'json'
must be set.
contentType:'application/json; charset=utf-8'
must be set.
- the data sending to the server must be JSON encoded.
To do all these I use datatype
, ajaxGridOptions
and serializeGridData
parameters of jqGrid. I do JSON encoding with JSON.stringify
function (the corresponding JavaScript can be downloaded from http://www.json.org/js.html).
Then the received data must be decoded. I do this with my favorite feature of jqGrid - jsonReader
with functions (see http://stackoverflow.com/questions/2835957/jquery-with-asp-net-mvc-calling-ajax-enabled-web-service/2836817#2836817 and http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#jsonreader_as_function).
At the end we use loadonce: true
which change the datatype
of jqGrid from 'json'
to 'local'
and we can use immediately all advantage of local paging, sorting and advanced searching existing since jqGrid version 3.7.
If you do want make server side paging, sorting and searching (or advanced searching) with ASMX web service it is also possible. To save a little place here and to separate code examples I will post the corresponding example in your other question http://stackoverflow.com/questions/3161302/jqgrid-page-1-of-x-pager/3161542#3161542 (see UPDATED part).