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
});
}
Hello,
When you try to reload your view model with a new set of data, the grid will try to find the differences between the two and apply them without re-rendering itself. This is one of the key features of the grid's Knockout integration, however it can be slow with very big chunks of data, which might be what's causing this freezing. What is the amount of records the server sends in your case? Could you please share which version of Ignite UI you are using?
I am looking forward to hearing from you!
Best regards,
Stamen Stoychev
Hi,
I don't think it is a recordsize issue because I am only returning about 100 results. Is it possible to do without hand coding the view model and just using mapping plug in? The example Infragistics provides is mapped by hand.
I believe that I am using the latest version of igniteUI, which is in the download is a subfolder within the Infragistics/2013.2 folder. Incidently I have found that Infragistics needs to abandon the mapping plugin and go with a rewrite that is called viewModel. In my testing it is 100 times faster on data load.