Forum


04:00

09/02/2009

have an simple WS with method:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetGridData()
{
// Load a list
InitSessionVariables();
SA.DB.DenarnaEnota.DenarnaEnotaDB db = new SAOP.SA.DB.DenarnaEnota.DenarnaEnotaDB();
DataSet ds = db.GetLookupForDenarnaEnota(SAOP.FW.DB.RecordStatus.All);
// Turn into HTML friendly format
List<GetGridData> summaryList = new List<GetGridData>();
JavaScriptSerializer js = new JavaScriptSerializer();
foreach (DataRow dr in ds.Tables[0].Rows)
{
GetGridData summary = new GetGridData();
summary.DenarnaEnotaID = dr["DenarnaEnotaID"].ToString();
summary.Kratica = dr["Kratica"].ToString();
summary.Naziv = dr["Naziv"].ToString();
summary.Sifra = dr["Sifra"].ToString();
summaryList.Add(summary);
}
return js.Serialize(summaryList);
}
i defined jqGrid as follows:
jQuery(document).ready(function(){
jQuery(”#list”).jqGrid({
datatype : function (postdata) { jQuery.ajax({ url:'../../AjaxWS/TemeljnicaEdit.asmx/GetGridData',
data:”{}”,
dataType:”json”,
type: “POST”,
contentType: “application/json; charset=utf-8″,
complete: function(jsondata,stat){
if(stat==”success”)
{
var thegrid = jQuery(”#list”)[0];
var myjsongrid = eval(”(”+jsondata.responseText+”)”);
var result = thegrid.addJSONData(myjsongrid);
thegrid.addJSONData(myjsongrid);
}
}
}
);
},
colNames:['DenarnaEnotaID','Kratica', 'Sifra', 'Naziv'],
colModel:[ {name:'DenarnaEnotaID',index:'DenarnaEnotaID', width:100},
{name:'Kratica',index:'Kratica', width:100},
{name:'Sifra',index:'Sifra', width:100},
{name:'Naziv',index:'Naziv', width:100, align:"right"}],
rowNum:10,
rowList:[10,20,100],
pager: jQuery('#pager'),
sortname: 'DenarnaEnotaID',
viewrecords: true,
sortorder: “desc”,
caption:”Vrstice”,
cellEdit: true }).navGrid('#pager',{edit:false,add:false,del:false});
});
WS is invoked and returns JSON like this (this is a value of variable myjsongrid which is supplied to addJasonData).
“[{\\"DenarnaEnotaID\\":\\"18\\",\\"Kratica\\":\\"BAM\\",\\"Sifra\\":\\"977\\",\\"Naziv\\":\\"Konvertibilna marka\\"},{\\"DenarnaEnotaID\\":\\"19\\",\\"Kratica\\":\\"RSD\\",\\"Sifra\\":\\"941\\",\\"Naziv\\":\\"Srbski dinar\\"},{\\"DenarnaEnotaID\\":\\"20\\",\\"Kratica\\":\\"AFN\\",\\"Sifra\\":\\"971\\",\\"Naziv\\":\\"Afgani\\"},{\\"DenarnaEnotaID\\":\\"21\\",\\"Kratica\\":\\"ALL\\",\\"Sifra\\":\\"008\\",\\"Naziv\\":\\"Lek\\"},{\\"DenarnaEnotaID\\":\\"22\\",\\"Kratica\\":\\"DZD\\",\\"Sifra\\":\\"012\\",\\"Naziv\\":\\"Alžirski dinar\\"},{\\"DenarnaEnotaID\\":\\"23\\",\\"Kratica\\":\\"AOA\\",\\"Sifra\\":\\"044\\",\\"Naziv\\":\\"Bahamski dolar\\"},{\\"DenarnaEnotaID\\":\\"30
....
{\\"DenarnaEnotaID\\":\\"89\\",\\"Kratica\\":\\"MKD\\",\\"Sifra\\":\\"807\\",\\"Naziv\\":\\"Denar\\"},{\\"DenarnaEnotaID\\":\\"90\\",\\"Kratica\\":\\"MWK\\",\\"Sifra\\"DenarnaEnotaID\\":\\"1\\",\\"Kratica\\":\\"SIT\\",\\"Sifra\\":\\"705\\",\\"Naziv\\":\\"Slovenski tolar\\"}]“
AddJason data simply does not work. Grid is empty and no errors reported. Any idea ?
ASP.NET WebMethods add a "d" as the container object for the JSON response it sends back (I think this is for some security purposes). You need to account for this in your addJSONData call as follows:
if(stat==”success”)
{
jQuery(”#list”)[0].addJSONData(jsondata.d);
}
No eval statement is needed. Hope this helps!
22:35

09/02/2009

Thanks for the answer but didn't help. Nothing happen again (no eval just jsondata.d). if i try to make alert(jsondata.d) it is undefied … I do not realy lknow what is missing here … JSON seems OK, definitions seems OK, everything looks like by the book…but it does not work as supposed.
Maybe it is some issue connected because i am using prototype library as well ???? But so far it doe not conflict..
I have also modified JSON so now it looks liki in sample on live demo ... still not ok 🙁
NEW JSON (contaons page, total, records, ...):
{"page":"1","total":"10","records":"160","rows":[{"id":"18","cell":"["18","BAM","Konvertibilna marka","977"]"},{"id":"19","cell":"["19","RSD","Srbski dinar","941"]"},{"id":"20","cell":"["20","AFN","Afgani","971"]"},{"id":"21","cell":"["21","ALL","Lek","008"]"},{"id":"22","cell":"["22","DZD","Alžirski dinar","012"]"},{"id":"23","cell":"["23","AOA","Kvanza","973"]"},{"id":"24","cell":"["24","XCD","Vzhodnokaribski dolar","951"]"},{"id":"25","cell":"
..................
["13","PLN","Poljski zlot","985"]"},{"id":"14","cell":"["14","SEK","Švedska krona","752"]"},{"id":"15","cell":"["15","SKK","Slovaška krona","703"]"},{"id":"16","cell":"["16","USD","Ameriški dolar","840"]"},{"id":"17","cell":"["17","XXX","Nobena valuta","000"]"},{"id":"1","cell":"["1","SIT","Slovenski tolar","705"]"}]}
Again thanks….
10:46

Moderators
30/10/2007

Hello
function(jsondata.responseText,stat) instead
Regards
Tony
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:
49 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