This is driving me crazy. I am building a Hot Towel/SPA app. I'm successfully retrieving data from our server and filling an observable array. I cannot figure out how to bind it to the igGrid.
I am trying to use a KnockoutDataSource.
In the view model, I have datasource, and I define the vm:
var datasource;
var vm = { activate: activate, title: 'ig Item Details', itemNumber: ko.observable(), companyNumber: ko.observable(""), warehouse: ko.observable(""), histories: ko.observableArray([]), viewAttached: function (view) { $("#tabs").tabs(); setupTransactionHistoryGrid(); getTransactionHistory({ pageNum: 0, pageSize: 25 }, vm.itemNumber, vm.warehouse); }
setupTransactionHistoryGrid:
function setupTransactionHistoryGrid() { datasource = new $.ig.KnockoutDataSource( { dataSource: vm.histories, type: 'json', callback: 'render' }); datasource.dataBind(); $("#transactionHistoryGrid").igGrid({ columns: [ { headerText: "Transaction Code", key: "IATRCD", type: "string" }, ], width: "500px", dataSource: datasource }); }
HTML:
<table id="transactionHistoryGrid"></table>
When I run this, I get this exception when attempting to create the datasource:
Unhandled exception at line 13, column 221 in http://localhost:58210/Scripts/ig/js/extensions/infragistics.datasource.knockoutjs.js0x800a138f - Microsoft JScript runtime error: Unable to get value of the property 'toJS': object is null or undefined
That line:
options.dataSource=ko.mapping.toJS(options.dataSource)
Adding the knockout mapping plugin didn't help. I'm still struggling.
Hi jbaumgartner,
Please let me know if you still need assistance with this.
You are most likely receiving this error because you are missing the ko.mapping plugin.
Please see the following page for more information on this.
http://knockoutjs.com/documentation/plugins-mapping.html
*Please note this site is not owned or maintained by Infragistics.
You can also see an example of how to set up the igGrid with knockout here:
http://ko.infragistics.com/products/jquery/sample/grid/grid-knockoutjs-integration
Please let me know if you need further assistance with this and I will be glad to help.
13.1.20131.2039
Hello Jon,
What version (and build number) of the Ignite UI controls are you using?
Best regards,Martin PavlovInfragistics, Inc.