Forum


01:33

07/08/2011

Hello. After many attempts, and too many searches to mention, I'm finally able to load JSON data from my web service. Here is what I have:
$("#list").jqGrid({
url: 'FileServices/GetList/JSA',
datatype: function (postdata) {
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8″,
dataType: "json",
data: postdata,
url: "FileServices/GetList/JSA",
complete: function (xhr, stat) {
if (stat == "success") {
var jsonObject = (eval("(" + xhr.responseText + ")"));
$('#list')[0].addJSONData(JSON.parse(jsonObject));
}
}
});
},
jsonReader: { root: "rows", page: "page", total: "total",
records: "records", repeatitems: true, cell: "cell", id: "id" },
colNames: ['Id', 'Number', 'Facility', 'Department', 'Category', 'Job Title'],
colModel: [
{ name: 'Id', index: 'Id', width: 55 },
{ name: 'Number', index: 'Number', width: 90 },
{ name: 'Facility', index: 'Facility', width: 80 },
{ name: 'Department', index: 'Department', width: 80 },
{ name: 'Category', index: 'Category', width: 80 },
{ name: 'Job_Title', index: 'Job_Title', width: 150, sortable: false }
],
pager: '#pager',
rowNum: 10,
rowList: [10, 20, 30],
sortname: 'Id',
height: 'auto',
sortorder: 'desc',
viewrecords: true,
gridview: true,
caption: 'My first grid'
}).navGrid("#pager");
When I try to click on a column to sort, it doesn't work. I read that you need the reloadGrid trigger added but I'm not sure what that would go. I tried it in a couple of places and that seemed to send the grid in some crazy infinite loop or something.
Now using the code below, the data loads fine and the sorting works great. But the data call is done outside of the main call. I like the idea of having everything in the single call (like above).
$("#list").jqGrid({
url: 'FileServices/GetList/JSA',
datatype: 'jsonstring',
jsonReader: { root: "rows", page: "page", total: "total", records: "records", repeatitems: true, cell: "cell", id: "id" },
mtype: 'GET',
colNames: ['Id', 'Number', 'Facility', 'Department', 'Category', 'JobTitle'],
colModel: [
{ name: 'Id', index: 'Id', width: 55 },
{ name: 'Number', index: 'Number', width: 90 },
{ name: 'Facility', index: 'Facility', width: 80 },
{ name: 'Department', index: 'Department', width: 80 },
{ name: 'Category', index: 'Category', width: 80 },
{ name: 'Job_Title', index: 'Job_Title', width: 150, sortable: false }
],
pager: '#pager',
rowNum: 10,
rowList: [10, 20, 30],
sortname: 'Id',
height: 'auto',
sortorder: 'desc',
viewrecords: true,
gridview: true,
caption: 'My first grid'
}).navGrid("#pager″);
$("#list").clearGridData();
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8″,
dataType: "json",
data: null,
url: "FileServices/GetList/JSA",
complete: function (xhr, status) {
var data = JSON.parse(xhr.responseText);
$("#list").jqGrid('setGridParam', { datatype: 'jsonstring', datastr: data });
$("#list").trigger('reloadGrid');
}
});
Does anything stand out to what I'm missing?
Thank you very much!
dzangger67
03:54

07/08/2011

I just added this:
complete: function (xhr, stat) { if (stat == "success") { var data = JSON.parse(xhr.responseText); $("#list").jqGrid('setGridParam', { datatype: 'jsonstring', datastr: data }); $("#list").trigger('reloadGrid'); } }
and it seems to work. I just hope this is the correct method of doing this.
dzangger67
19:47

Moderators
30/10/2007

Hello,
To complex solution.
You will need just to write some server side logic when sort is performed. Just read what we pass as parameters when we do sort.
Regards
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
82 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66