My goal is simply to generate a viewModel via Knockout.Mapping, bind a igGrid to the viewModel, and then refresh the viewModel and grid via an ajax call to a controller that returns JSON. I am using VisualStudio 2013 and MVC 5. I have the correct libraries referenced. I am able to get the Infragistics Knockout Integration sample to work correctly, but in the sample there are a lot of hard coded references to column names. I don't want to reference the column names directly, but rather rely on knockout mapping to create my observable viewModel. The initial model binding works fine, and the populated grid is correctly displayed. When I attempt to refresh the grid after the Ajax call, the browser freezes and I have to terminate IE. Can someone show me a simple example of how this can be accomplished?
HTML - <table id="grid" data-bind="igGrid: { dataSource: myData, primaryKey: 'ID', features: [{ name: 'Updating', editMode: 'none', enableAddRow: false, enableDeleteRow: true, columnSettings: [ ] }] }"></table>
JavaScript -
$(document).ready(function () {
var model = @Html.Raw(Json.Encode(Model))
viewmodel = ko.mapping.fromJS(model)
ko.applyBindings(viewmodel); };
function getRefreshedModel()
{
$.ajax({
url:"/Controller/Action/",
type:'post',
data: dataString,
contentType:'application/json',
success: function (results) { ko.mapping.fromJS(results, viewmodel); } //refresh the model and grid
});
}
Hi,
Please let us know if you need our help. I will check after Jan 15th .
Hi, thank you for checking back, Dimi. I have been on vacation in South America (returning Jan 15th to the US), so it is taking me a while to get back to your last communication. I don't have any configuration differences that I am aware of that would affect the ability to implement paging. It is possible that I have a JavaScript library conflict, so I will try a stripped down example next.
I am just checking if the latest reply helped you out and if you require any further assistance on the matter.
Hello,
In my original sample, I avoided adding the data-bind attribute to the grid's element initially so that the grid options were not passed around redundantly. You could however do that to save yourself from having to first bind the whole model and then the grid separately on the initial load of the page. The other solution is to stringify the gridOpts object and add the attribute dynamically before calling ko.applyBindings(model).
As for the issue with Paging, I added Paging without any options to my sample and it worked without issues. Do you use some specific configuration which I am not aware of?
Best regards,
Stamen Stoychev
I attempted to implement paging in the grid, but when I click on the "next" button, I get a JavaScript error. It seems that this may be related to the binding problem as the grid attempts to bind to the next group of data.
Error Msg - "JavaScript runtime error: Unable to get property 'dataType' of undefined or null reference"
Occurs in Function - "function applyBindingsToNodeInternal(node, sourceBindings, bindingContext, bindingContextMayDifferFromDomParentElement)" during this section - "// Run init, ignoring any dependencies"