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)
Hello Jon,
What version (and build number) of the Ignite UI controls are you using?
Best regards,Martin PavlovInfragistics, Inc.
13.1.20131.2039
Hi jbaumgartner,
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.
Please let me know if you still need assistance with this.
Adding the knockout mapping plugin didn't help. I'm still struggling.
We do not recommend creating instances of our datasources for use with our controls. The recommended approach to bind to a KO viewmodel and observable array is through the data-bind attribute as with binding knockout with other elements.
Please see my attached sample for an example of how to achieve this. You can also find further samples here:
Please let me know if you have any further questions or concerns with this and I will be glad to help.
Yeah, I've done that. It always works if I manually create the data, as you have done in your example. As soon as I try to retrieve actual data from the backend via breeze, I end up with a valid recordset, but the grid shows blank values in the grids.
Please let me know if you still need assistance with this issue. If so, please provide a sample for us to better research this issue.
We need more information on this issue. Would it be possible for you to upload a sample that reproduces this behavior for us to look into more closely and have a better understanding of the issue?
Looking forward to hearing from you.
I am currently discussing this issue with my supervisor for further guidance on this issue.
I will have another update for you by Monday.