I am using knockout observable array to bind the html table like this
<div>
<button data-bind='click: update'>Get Data</button>
</div>
<div id="divLanguage" style="overflow: hidden;">
<table style="width: 760px;">
<tr>
<td style="padding: 0px;width: 100px;font-weight: bold">name</td>
<td style="padding: 0px;width: 70px;font-weight: bold">select</td>
</tr>
</table>
<div id="language" style="overflow: auto;height: 540px;">
<table id="Table1" class="gridHover" style="width: 760px;">
<tbody data-bind="foreach: queryResult">
<tr>
<td style="padding: 0px;text-align: left;width: 100px" data-bind="text: name"></td>
<td style="padding: 0px;text-align: left;width: 70px">
<input type="checkbox" />
</td>
</tr>
</tbody>
</table>
</div>
The view model is
var initialData = [{
id: 1,
name: "Well-Travelled Kitten",
sales: 352,
price: 75.95,
whatever: 10
}, {
id: 2,
name: "Speedy Coyote",
sales: 89,
price: 190.00,
whatever: 100
}, ];
function viewModel() {
var self = this;
self.queryResult = ko.observableArray();
this.update = function (data) {
//this is an ajax call and return dateset back
$.each(initialData, function (index, item) {
self.queryResult.push(item);
});
};
}
ko.applyBindings(new viewModel());
You can see that checkbox is not binded to any field. I know that we can use checked binding to bind data to checkbox. Problem is that i cant bind checkbox to any column because i will getting information on fly. In observable array i have property called id and i will get information if that id has value true or false. Depending upon that i want to bind the checkbox.
I really dont know how to proceed with this. Does anyone have idea about binding checkbox without any column. Also once we bind, how can we get value from checkbox when we check or uncheck it?
Here is the Fiddle
idistrueorfalse? - Th4t Guy