Hi,
I am using Infragistics 2011 vol 2 JQUERY Grid. I need to bind the igGrid datasource to the datatable object available at server side .aspx.CS file.
Thanks.
Okay here's my final solution. I call destroy each time per another thread about reloading that I found... I should really write a blog for you guys. :)
function getData() {
//Grid must be destroyed rather than reloaded per a bug that is mentioned//in this forum post. Kind of gross, but it works.//http://forums.infragistics.com/forums/p/68376/346580.aspx$('#SearchResults').igGrid('destroy');$.ajax({type: 'POST',url: 'SearchService.asmx/SearchEntity',data: "{SearchCriteria: '" + $("#SearchText").val() + "'}",contentType: 'application/json; charset=utf-8',dataType: 'json',success: function (msg) {
var obj = jQuery.parseJSON(msg.d);
$("#SearchResults").igGrid({autoGenerateColumns: false,columns: [{ headerText: "Id", key: "Id", width: "50px", dataType: "number" },{ headerText: "Name", key: "Name", width: "100px", dataType: "string" },{ headerText: "Age", key: "Age", width: "50px", dataType: "string" },{ headerText: "Address", key: "Address", width: "100px", dataType: "string" }],dataSourceType: 'json',dataSource: obj,height: '300px'});},error: function (xhr, ajaxOptions, thrownError) {alert("Something bad happened. Code: " + xhr.status + ". Error: " + xhr.responseText);}});}});
Okay I found the problem. What I was receiving from the asmx was a json string that needed to be converted to a JSON object. For anyone else trying to do what I'm doing, ultimately the code ended here's what I ended up doing:
Here's the whole block of code (going to rerwite this so I rebind the grid rather than create it new each time now):
function getData() { $.ajax({ type: 'POST', url: 'SearchService.asmx/SearchEntity', data: "{SearchCriteria: '" + $("#SearchText").val() + "'}", contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (msg) {
$("#SearchResults").igGrid({ autoGenerateColumns: false, columns: [ { headerText: "Id", key: "Id", width: "50px", dataType: "number" }, { headerText: "Name", key: "Name", width: "100px", dataType: "string" }, { headerText: "Age", key: "Age", width: "50px", dataType: "string" }, { headerText: "Address", key: "Address", width: "100px", dataType: "string" } ], dataSourceType: 'json', //responseDataKey: 'd', dataSource: obj, height: '300px' }); }, error: function (xhr, ajaxOptions, thrownError) { alert("Something bad happened. Code: " + xhr.status + ". Error: " + xhr.responseText); } }); }
So this is the string I get from msg in ajax callback.[{"Id":1,"Name":"Jack","Age":"33","Address":"Somewhere"},{"Id":2,"Name":"Joe","Age":"31","Address":"Somewhere"},{"Id":3,"Name":"Jill","Age":"24","Address":"Somewhere"}]
As you can see, it's different in that it's missing "d:" at the very beginning. However, if I remove the "responseDataKey: 'd'," from the grid, I would think it should bind, but it doesn't.
So this is what fiddler says is being sent and above is what's actually showing up in my msg parameter:{"d":"[{\"Id\":1,\"Name\":\"Jack\",\"Age\":\"33\",\"Address\":\"Somewhere\"},{\"Id\":2,\"Name\":\"Joe\",\"Age\":\"31\",\"Address\":\"Somewhere\"},{\"Id\":3,\"Name\":\"Jill\",\"Age\":\"24\",\"Address\":\"Somewhere\"}]"}
So I guess jquery/ajax call is smart in that it strips off the "d," but without the stripped off "d" nothing will bind to the grid no matter what I try.
Going to try this afrer I figure out what's up with the data I'm getting back from my web service.
Yes I agree Fiddler FTW. I will post more shortly.
triffle said:Finally, let me explain what I am trying to do... I don't want any data loaded into the grid until a user hits the search button.