I have an igGrid bound to a knockout view model's observable array. Separately, there is a combo box that users can select an item from. When an item is selected, a new object is pushed to the observable array. I can see a new row in the grid with the correct data in it, but I also see a "TypeError: rec is null" error and am then unable to add another row or edit the existing rows. The error seems to be coming from infragistics.ui.grid.knockout-extensions.js, but I haven't the foggiest idea what the cause is. I've been able to validate that the new HoldingsModel is getting created correctly and being appended to the holdings observable array. Not sure what the grid is doing after that, but I wonder if some of the bindings for individual cells is getting messed up.
I'd appreciate any help that could point me in the right direction.
Here are the relevant details of my code:
HTML:<table id="accountAddHoldings" data-bind="igGrid: holdingsGridOptions"></table>JS://Main view model
var AccountCreationViewModel = function() { var self = this;
//Array of table for the data
self.holdings = ko.observableArray([]);
//Config for the igGrid
self.holdingsGridOptions = { primaryKey: "securityId", dataSource: holdings, width : "100%", autoCommit : true, autoGenerateColumns : false, columns : [ {headerText: "Name", key: "securityName", width: "120px"}, {headerText: "Id", key: "securityId"}, {headerText: "Segment", key: "segment"}, {headerText: "Quantity", key: "quantity"}, {headerText: "Value", key: "value"}, {headerText: "Expected Quantity", key: "expectedQuantity"}, {headerText: "Expected Value", key: "expectedValue"}, {headerText: "Quantity Drift", key: "quantityDrift"}, {headerText: "Value Drift", key: "valueDrift"}, {headerText: "Price", key: "securityLastPrice"} ], features : [ { name: "Selection", editMode: "row" }, { name: "Updating", editMode: "row", enableDeleteRow: true, columnSettings: [ { columnKey: "securityId", readOnly: true }, { columnKey: "securityName", readOnly: true }, { columnKey: "segment", readOnly: true }, { columnKey: "quantityDrift", readOnly: true }, { columnKey: "value", readOnly: true }, { columnKey: "valueDrift", readOnly: true }, { columnKey: "securityLastPrice", readOnly: true }, { columnKey: "quantity", editorType: "numeric", readOnly: false }, { columnKey: "expectedQuantity", editorType: "numeric", readOnly: false }, { columnKey: "expectedValue", editorType: "currency", readOnly: false } ] } ]}
Thanks for your help!
}
//Model for items in AccountCreationViewModel().holdings
var HoldingModel = function(securityName, securityId, segment, securityLastPrice) { var self = this; self.securityName = securityName; self.securityId = securityId; self.segment = segment; self.securityLastPrice = securityLastPrice; self.quantity = ko.observable(0); self.expectedQuantity = ko.observable(0); self.expectedValue = ko.observable(0); self.quantityDrift = ko.pureComputed(function() { return Math.abs(this.expectedQuantity() - this.quantity()); }, self); self.valueDrift = ko.pureComputed(function() { return Math.abs(this.expectedValue() - this.value()); }, self); self.value = ko.pureComputed(function() { return this.quantity() * this.securityLastPrice; }, self); };
// Called on the "selectionChanged" event of the combo; theoretically adds a new item to the grid
selectionChanged: function(evt, ui) { var security = ui.items[0].data; viewModel.holdings.push(new HoldingModel(security.ticker, security.pk, security.segment, security.last_price)); }
Sure,
It's already logged and resolved into our internal system, so stay tuned for the next Service Release.
Yep, that did it. Thanks for the heads up. Do you know if this item is on the roadmap and planned for a specific release? Or just a future item?
Hello,
Knockout data source is trying to set all properties, at this point it doesn't perform check is they are read only. We plan to add a backlog item for this and support them in the future, but at this point you'll have to add the write properties for the computed properties.
Ah, interesting. Yes, that does seem to fix the problem of the wrong display values. Thanks!
Looks like I'm not quite out of the woods yet though. Now I'm trying to edit the row I add, and when I click "Done" on the row editing I'm getting the following error/stacktrace:07:52:11.983 Error: Cannot write a value to a ko.computed unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters.computedObservable() knockout-3.4.0.debug.js:1879$.ig.KnockoutDataSource<._updateRow() infragistics.datasource.knockoutjs.js:13$.ig.KnockoutDataSource<._commitTransaction() infragistics.datasource.knockoutjs.js:13$.ig.DataSource<._commitTransactionsByRowId() infragistics.core.js:262$.ig.DataSource<.commit() infragistics.core.js:262$.ig.DataSource<.updateRow() infragistics.core.js:262$.ig.KnockoutDataSource<.updateRow() infragistics.datasource.knockoutjs.js:13makeFn/<() infragistics.core.js:232._updateRow() infragistics.lob.js:501$.widget/</proxiedPrototype[prop]</<() jquery-ui-1.10.4.custom.js:401._endEdit() infragistics.lob.js:500$.widget/</proxiedPrototype[prop]</<() jquery-ui-1.10.4.custom.js:401._doneButtonClick() infragistics.lob.js:499$.widget/</proxiedPrototype[prop]</<() jquery-ui-1.10.4.custom.js:401.proxy/proxy() jquery-1.10.2.js:827jQuery.event.dispatch() jquery-1.10.2.js:5094jQuery.event.add/elemData.handle() jquery-1.10.2.js:47661 knockout-3.4.0.debug.js:1879:23
If you look at my configuration and model, you'll see that the only editable fields in the table correspond to plain old observables, rather than computed observables. Is the grid trying to write the readOnly fields to the model? I can always add write properties in to those computed observables, but that seems a little strange.