When I call my page to grab my JSON data and it returns records I can call data in the object or grid.
If the JSON comes back with no data and I try to add records and reference I get a null reference error on either the grid or the js object.
Is there a way to initialize the variable to that is no initial JSON comes back then it will not be null. It seems that igGrid can't add data if no initial rows come back.
Hello Donnie,
The way you try to set the data source is not correct. Using this code:
$("#TSDefaultGrid").igGrid({ dataSource: gridData});
will try to create a new instance of the grid on top of the existing. That's why the grid is throwing an error.
The correct way to set the data source after the grid is created is to use the following code:
$("#TSDefaultGrid").igGrid("option", "dataSource", gridData);
It is worth to mention that igGrid has the remote data binding functionality out of the box so you don't need to make and AJAX call by yourself. Just set the dataSource property to the Url (on initialization) of your endpoint like this:
$("#TSDefaultGrid").igGrid({
dataSource: SitePath + "Timesheet/GridData.aspx?tsid=<%=tsid%>",
// some more igGrid opitions
});
You should set the responseDataKey property if you return object from your remote endpoint. The responseDataKey points to the property in the object which contains the actual array with the data.
You may also need to set the dataSourceType option to "json".
Hope this helps,
Martin Pavlov
Infragistics, Inc.
I am using an AJAX call to a C# method. I use JsonWriter to build a JSON string and return it.
I am initializing my JS variable as var GridDate. If the AJAX call returns something the string get populated.
I am called this in the $.ig.loader
var json = (function () {
$.ajax({ 'async': false, 'global': false, 'url': (SitePath + "Timesheet/GridData.aspx?tsid=<%=tsid%>"), 'dataType': "json", 'success': function (data) { gridData = data; } }); return json; })();
$("#TSDefaultGrid").igGrid({ dataSource: gridData });
As you see gridDate get the JSON return. Maybe try to put something in my gridData variable if nothing is returned? Or initialize the variable to the schema of my JSON?
Hi Donnie,
Which method are you using to add records to the grid?
Are you trying to change the data source after the grid is created?
Thanks in advance,