Hi all,
I encountered an error when binding data returned from web service to igGrid. The error is occurred in ig.ui.min.js when JSON.parse(s) is called.
stringToJSONObject:function(s){var data={};try{data=JSON.parse(s)}catch(e)
The message is "there was an error in parsing/evaluating json string: Syntax Error"
I have the following from code on my server side:
List<MyTransaction> Transactions = new List<MyTransaction>
{ new MyTransaction{ TransactionID=12235, PlanID=63, Premium=225f},
new MyTransaction{ TransactionID=12236, PlanID=64, Premium=256f},
new MyTransaction{ TransactionID=12237, PlanID=77, Premium=355f}
};
[WebMethod]
public List<MyTransaction> GetAllTransactions()
{return Transactions;}
In my aspx page (Version 1) I have:
var url = "/Vertex/CarService.asmx/GetAllTransactions"; var json = new $.ig.DataSource({ type: "json", dataSource: url });
$("#igGrid").igGrid({ virtualization: false, autoGenerateColumns: false, jQueryTemplating: false, columns: [ { headerText: "TransactionID", key: "TransactionID", dataType: "number", width: "150px" }, { headerText: "PlanID", key: "PlanID", dataType: "number", width: "120px" }, { headerText: "Premium", key: "Premium", dataType: "number", width: "400px" } ],
dataSource: json, responseDataKey: "d", scrollbars: true, height: '800px', features: [ { name: 'Paging', pageSize: 20 }, { name: 'Sorting' }, { name: 'Filtering', filterDropDownItemIcons: false, filterDropDownWidth: 200 } ] }); }
However, if I change my aspx into the following(version 2), the data binding is OK. That means using ajax call to get data first, then data binding is OK.
What am I missing in version 1? should I use responseDataKey: "d" option?
$(function () {
$.ajax({
type: "POST",
url: "/Vertex/CarService.asmx/GetAllTransactions",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
records = response.d;
$("#igGrid").igGrid({ virtualization: false, autoGenerateColumns: false,
columns: [ { headerText: "TransactionID", key: "TransactionID", dataType: "number", width: "150px" }, { headerText: "PlanID", key: "PlanID", dataType: "number", width: "120px" }, { headerText: "Premium", key: "Premium", dataType: "number", width: "400px" } ],
dataSource: records,
scrollbars: true, height: '400px', features: [ { name: 'Paging', type: "local", pageSize: 5 }, { name: 'Sorting' }, { name: 'Filtering', type: 'local', filterDropDownItemIcons: false, filterDropDownWidth: 200 } ] });
},
failure: function (msg) { $('#dailyTransaction').text(msg); }
});
Betty
You can try out my solution, posted few days back on stackoverflow
http://stackoverflow.com/questions/13294447/reloading-infragistics-grid
No problem, Betty :)It's all in a day's work.Cheers,Borislav
Hi Borislav,
That's really help. You are very
knowledgeable.
Hi Betty,Just to compliment on what Martin has already advised you on and to answer your current questions.
bettysun said:Why your igDataSource's default request is not "Get"? I thought this is by default.
bettysun said:Your api/developer's guide doesn't give me the impression that "remoteUrl" is required.
bettysun said: I don't remember responseContentType: "application/json; charset=UTF8;" is required either.
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
attribute on your service's method - that'll have the same effect. (A more detailed explanations is also available at http://stackoverflow.com/questions/2086666/wcf-how-do-i-return-clean-json)Cheers,Borislav
Martin,
You rock. it works now!!! I have been pulling my hair all the week.
Your api/developer's guide doesn't give me the impression that "remoteUrl" is required. I looked at your odata and wcf sample. I don't remember that remoteUrl is specified in the samples. Maybe I missed. I don't remember responseContentType: "application/json; charset=UTF8;" is required either.
You are just great!!!