I'm actually doing my project the editable grid, my data comes from the JSON and parsed to dictionary to have key and value and display on the table.
I have one more column to have 3 links, Modify, Validate and Cancel.
However, the value from input tag, after editing by user, cannot be updated to the label tag.
<table class="table table-hover"> <tbody data-bind="foreach: $root.testParams(parameters())"> <tr class="data-hover"> <td> <strong> <span id="key_params" data-bind="text:$data.key" /> </strong> </td> <td> @*display label and input for dictionary<value>*@ <input type="text" class="edit" data-bind="value:value,visible:$root.isItemEditing($data)" /> <label class="read" data-bind="text:value,visible:!$root.isItemEditing($data)" /> </td> <td> <a href="#" class="action" data-bind="click: $root.editData.bind($root),visible:!$root.isItemEditing($data)"> <i class="glyphicon glyphicon-edit"></i> Modify </a> <a class="action" href="#" data-bind="click: $root.applyData.bind($root),visible:$root.isItemEditing($data)"> <i class="glyphicon glyphicon-remove-circle"></i> Validate </a> <a class="action" href="#" data-bind="click: $root.cancelData.bind($root),visible:$root.isItemEditing($data)"> <i class="glyphicon glyphicon-remove-circle"></i> Cancel </a> </td> </tr> </tbody> </table>
config.js
function ConfigurationViewModel() { var self = this; self.testParams = mapDictionaryToArray; self.value = ko.observable(); self.parameters = ko.observableArray(); self.editingItem = ko.observable(); self.isItemEditing = function (datum) { return datum == self.editingItem(); }; self.editData = function (datu) { if (self.editingItem() == null) { self.editingItem(datu); } }; self.applyData = function () { self.editingItem(null); }; self.cancelData = function () { self.editingItem(null); }; }; $(document).ready(function () { ko.applyBindings(new RateScreenerConfigurationViewModel()); });
bus.js var mapDictionaryToArray = function (dictionary) { var result = []; dictionary = JSON.parse(dictionary); for (var key in dictionary) { if (dictionary.hasOwnProperty(key)) { result.push({ key: key, value: dictionary[key] }); } } return result; };