JSFiddle - React, Tailwind, and code Playground
HTML
<table>
<thead>
<th>Cust ID</th>
<th>ID</th>
<th>Product</th>
<th>Qty</th>
<th>Price</th>
</thead>
<tbody data-bind="foreach: items">
<tr data-bind="click: $parent.edit">
<td data-bind="html: custid"></td>
<td data-bind="html: id"></td>
<td data-bind="html: product"></td>
<td data-bind="html: qty"></td>
<td style="text-align: right" data-bind="html: price"></td>
</tr>
</tbody>
</table>
<!-- ko if: selectedItem() != null -->
<!-- ko with: selectedItem() -->
<div>
<div id="editBox">
<h3>Edit Item</h3>
<input data-bind="value: custid, valueUpdate: 'afterkeydown'" type="text"><br/>
<input data-bind="value: id, valueUpdate: 'afterkeydown'" type="text"><br/>
<input data-bind="value: product, valueUpdate: 'afterkeydown'" type="text"><br/>
<input data-bind="value: qty, valueUpdate: 'afterkeydown'" type="text"><br/>
<input data-bind="value: price, valueUpdate: 'afterkeydown'" type="text"><br/>
<button data-bind="click: $parent.save" class="btn">Save</button>
</div>
</div>
<!-- /ko -->
<!-- /ko -->
JavaScript
var orders = [ {
"product": ko.observable("product 1"),
"id": ko.observable("7556"),
"custid": ko.observable("21"),
"qty": ko.observable("1"),
"price": ko.observable("19.99")
}, {
"product": ko.observable("product 2"),
"id": ko.observable("7557"),
"custid": ko.observable("22"),
"qty": ko.observable("1"),
"price": ko.observable("29.99")
}, {
"product": ko.observable("product 3"),
"id": ko.observable("7558"),
"custid": ko.observable("23"),
"qty": ko.observable("1"),
"price": ko.observable("39.99")
},];
function AppViewModel() {
var self = this;
self.items = ko.observableArray(orders);
self.selectedItem = ko.observable(null);
self.save = function(item){
console.log(ko.toJSON(item));
}
self.edit = function(item){
self.selectedItem(item);
}
}
ko.applyBindings(new AppViewModel());