Forum
20:17
17/05/2010
Hi,
I'm new to this plugin.I want to show 2 grids on same .aspx page. Both calling different web method to load the data. I can see the layout for both grids. But only one grid is loaded.Not the other one.Here is the code for ajax call.
$(document).ready(function () {
$.extend($.jgrid.defaults,
{ datatype: 'json' },
{ ajaxGridOptions: { contentType: "application/json",
success: function (data, textStatus) {
if (textStatus == "success") {
var thegrid = $("#Grid1")[0];
thegrid.addJSONData(data.d);
thegrid.grid.hDiv.loading = false;
switch (thegrid.p.loadui) {
case "disable":
break;
case "enable":
$("#load_" + thegrid.p.id).hide();
break;
case "block":
$("#lui_" + thegrid.p.id).hide();
$("#load_" + thegrid.p.id).hide();
break;
}
}
}
}
});
jQuery("#Grid1").jqGrid({
url: 'AdvertiserRevenueActivityReport.aspx/GetDataTable',
datatype: 'json',
mtype: 'POST',
.........
});
I'm doing the same for another grid too.
$.extend($.jgrid.defaults,
{ datatype: 'json' },
{ ajaxGridOptions: { contentType: "application/json",
success: function (data, textStatus) {
if (textStatus == "success") {
var summgrid = $("#gridSummary")[0];
summgrid.addJSONData(data.d);
summgrid.drid.hDiv.loading = false;
switch (summgrid.p.loadui) {
case "disable":
break;
case "enable":
$("#load_" + summgrid.p.id).hide();
break;
case "block":
$("#lui_" + summgrid.p.id).hide();
$("#load_" + summgrid.p.id).hide();
break;
}
}
}
}
});
jQuery("#gridSummary").jqGrid({
url: 'AdvertiserRevenueActivityReport.aspx/GetSummaryDataTable',
datatype: 'json',
mtype: 'POST',
........
});
And I have two webmethod is .cs file.
[WebMethod]
public static s_GridSummary GetSummaryDataTable(string _search, string nd, int rows, int page, string sidx, string sord, int totalrows)
{}
[WebMethod]
public static s_GridResult GetDataTable(string _search, string nd, int rows, int page, string sidx, string sord, int totalrows)
{}
Following is also inside .cs file.
public struct s_GridResult
{
public int page;
public int total;
public int record;
public s_RowData[] rows;
}
public struct s_RowData
{
public int id;
public string[] cell;
}
public struct s_GridSummary
{
public int page;
public int total;
public int record;
public s_RowDataSummary[] rows;
}
public struct s_RowDataSummary
{
public int id;
public string[] cell;
}
I'm not sure the way I'm doing is right. Or what's a right way to do this?
Thanks,
00:11
10/08/2009
You has contain only in one grid because you use twice
{ ajaxGridOptions: { contentType: "application/json",
success: function (data, textStatus) {...} ...);
on the same page. The second call overwrite the setting of the first call and only one success function will be used. Inside of both success functions you use $("#Grid1")[0] or $("#gridSummary")[0] explicitly. So only one from the grids will be filled.
If you want to stay on you current code you can just place the ajaxGridOptions parameter in the jqGrid definition instead of overwriting $.jgrid.defaults.
The better would be not overwrite the success function at all and use only
or
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; }
}
One more small remark: You can use one type instead of two identical s_RowData and s_RowDataSummary and so identical s_GridResult and s_GridSummary. Look at this answer for example for more information.
Best regards
Oleg
Most Users Ever Online: 715
Currently Online:
55 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