Hey guys,
I think I've found a bug in one of your .js files. When I try to bind my grid to a REST service (which returns its data in JSON format), I get the following error:
Microsoft JScript runtime error: Unable to get value of the property 'length': object is null or undefined
If I break at that point, it breaks on the following statement:
var x, len = data.length;
(It is the first statement to run inside of the "_successCallback: function (data) {" function, which starts at line 28776 of infragistics.js, in the section with "Infragistics.Web.ClientUI Data Binding Plugin 12.2.20122.1021" in its header.)
Upon inspecting the data object, I see that it is null. The reason that I suspect there's a bug is because the very next statement does a check to see if data is null:
if ((data === undefined || data === null) && !this._alreadySet)
In the case that data is null, it'll never get to the if statement, because it will have thrown an exception in the previous statement.
In my debugging, if I break "len = data.length" onto its own line and skip over it, everything else runs just fine, and my grid seems to render properly.
Ultimately, I'd like to know if it's okay for me to just wrap the "len = data.length" inside of an "if (data != null)"? And if I am allowed to do that, can I set len to 0 in the "else" case?
(If you NEED a sample in order to reproduce, I can try to put one together for you, but the project I'm running has a lot of pages/controls/services/js, so it would take me a while to put it together. I'm hoping that the logic of checking for null after already using the object is enough to determine whether there's an inherent problem there or not.)
Thanks!
Jamie
Hi Jamie,
Is your problem solved related to the grid with Rest service.
I am also running into same problem, some time errors are coming if i try to solve those problems grid is not rendering with data. But i found data is coming to jquery functions. If possible, please provide your example i will check what's wrong going in my code.
My requirement is to generate grid with Java RESTful webservice which returns data in JSON format.
Regards
Sekhar.
Hi Sekhar,
I upgraded to service release 2056 and that fixed my problem! I am retrieving, inserting, and updating data via REST services now. (Haven't tested deletes yet.) As for an example, we're doing a lot of non-grid stuff intertwined with the grid stuff, but I'll try to pull the relevant bits here:
1. We have a manual AJAX call to a REST service that returns the column info first.function getColumnInfo() { jQuery.support.cors = true;
$.ajax( { type: "GET", url: 'Services/columnList', data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: getGridData, error: function (msg, url, line) { alert('error trapped in error: function(msg, url, line)'); alert('msg = ' + msg + ', url = ' + url + ', line = ' + line); } }); }
2. We use the column info to populate an ig.DataSchema. Note: The actual list of columns isn't at the root of columnDetailsJson... They're in a child variable called columnDetailsList. This is so that we can bring back a couple of other properties as well and store them at the root of the JSON object. (Like the pk value and the xmlpath --> we used to be setting xmlpath to an empty string, but we've since changed our data service to send the data back inside of a child variable, and we've set the xmlpath to the name of the child variable. Both ways worked for us... We wanted to send other info back with the data so we had to nest the actual data in a child variable so xmlpath now contains the name of the child variable.)function getGridData(columnData) { columnDetailsJson = columnData; dataSchema = new $.ig.DataSchema("xml", { fields: columnDetailsJson.columnDetailsList, searchField: columnDetailsJson.xmlpath }); bindGrid(); }
3. We bind the grid using the DataSchema and urls to the REST services. (Our GET rest service returns its data in JSON format, just like you need.)function bindGrid() { if (columnDetailsJson != null) { if (alreadyBound) { $('#placeHolder').igGrid('destroy'); }
var baseServiceString = "/Services/dataService";
var grid = $("#placeHolder").igGrid({ autoCommit: true, autoGenerateColumns: false, columns: columnDetailsJson.columnDetailsList, dataSource: baseServiceString, schema: dataSchema, restSettings: { create: { template: baseServiceString, batch: false }, update: { template: baseServiceString + "?id=${id}", batch: false }, remove: { template: baseServiceString + "?id=${id}", batch: false } }, dataBound: function (evt, ui) { //alert('dataBound fired'); }, dataRendered: function (evt, ui) { //alert('dataRendered fired'); }, primaryKey: columnDetailsJson.pkColumnKey, jQueryTemplating: false, autoAdjustHeight: true, width: "500px", features: [ { name: 'Updating', enableDataDirtyException: false, enableAddRow: true, enableDeleteRow: true, editMode: 'row', columnSettings: columnDetailsJson.columnDetailsList, showReadonlyEditors: false, startEditTriggers: "dblclick F2 enter" }, { name: "Selection", mode: "row", activeRowChanged: function (evt, ui) { activeRowChanged(evt, ui); } } ] });
alreadyBound = true; } }
4. The grid placeholder is just an HTML table.<table id="placeHolder" style="width:100%"></table>
Hope that helps. But we are now generating the grid using a RESTful web service which returns data in JSON format, so it can be done!