Hello,
I'm a bit new to KO, so I apologize. I have practically copied the example used here: http://es.infragistics.com/products/jquery/sample/grid/grid-knockoutjs-integration
If I load up the object (referred to by db in the sample code) then the grid will initialize with all of the data properly.
If I put the ajax call in a function and bind it to a button, I can't get the data in the grid to load/refresh after the call. I've made sure that the ajax call is being made and the JSON is coming back. Is there another API I need to hook into the grid to refresh the data?
Thanks
Hello Alex ,
You can change the data source of the igGrid in runtime by invoking the following line just after the rebind:
ko.applyBindings(moPeopleVM);
For additional reference on this you could check the attached sample. In order to run it just add the latest Infragistics scripts in the js and css folders.
Please let me know if this helps.
Hello Alex,
I was just wondering did you have a chance to try my suggestion. If you still need any assistance on the matter, please do not hesitate to ask.
Apologies Elena,
I was out all week last week. I'll be testing this again starting in a few minutes and let you know.
Ah, I seem to be erroring out before I can get to the rebinding.
I have this in the console: Uncaught TypeError: Cannot read property 'null' of undefined (thrown by the ig.grid knockout-extension).
The line that throws this error is from inside the viewmodel when I make the AJAX call:
success: function (data) { self.shows.removeAll(); $.each(data, function (key, val) { self.shows.push(val); <--- error });
}
The data coming back from the call is one big object, some of the properties are null (would that cause this?).
self.shows is an observableArray
Sorry to keep replying. Interestingly, I got it to the point where that error only gets thrown the first time I make the call. Subsequent calls work just fine, and the grid updates (well, I can see the total rows is going up but no columns appear).
I have got a similar problem. I am trying to reload a grid using an AJAX call to an ASP.NET service. The service provides me with the new grid data. I tested this by adding another record using a second instance of the page. When I press the reload button I made, I can see the AJAX request and it actually returns the data including the new record I added.
So in my code I use knockout mapping to convert the JSON into an knockout ViewModel and set my ViewModel with the converted object.
MYNAMESPACE.gridFunctions.prototype.refresh = function (data) { if (data == undefined) { $(".ajax-loader").css("display", "block"); MYNAMESPACE.gridFunctions.prototype.read(undefined, MYNAMESPACE.gridFunctions.prototype.refresh) return; } MYNAMESPACE.mainViewModel = ko.mapping.fromJS(data); ko.applyBindings(MYNAMESPACE.viewModel); $(".ajax-loader").css("display", "none"); };
The read funtion gets a JSON string using JQuerys AJAX method. It all seems to be working fine but when I use ko.applyBindings() my grid stays the same even when my ViewModel has in fact changed (when I check it manually using the console)
Am I forgetting something?
EDIT:
I was using MYNAMESPACE.mainViewModel to set it, but this doesn't work because I was trying to use it as a pointer which of course it isn't.
EDIT2:
I had to use JQuery.parseJSON() to avoid an error from JQuery, I don't know why exactly, but it said there was an error in the JSON syntax.
MYNAMESPACE.viewModel.books = ko.mapping.fromJS($.parseJSON(data));
Hi Alex,
Could you provide me with small sample where this issue present so I could research it further.
Thanks in advance.