I am really not sure how to solve. However i am quite close the solution and now just need one small help from you experts here. My working fiddle is here. When the page loads the 2 checkboxes are checked. My view is binded as below
<tbody data-bind="foreach: dataOne">
<tr data-bind="css: { 'makeBold': $root.duplicates.indexOf(name1) !== -1 }" >
<td data-bind="text: id"></td><td > </td>
<td data-bind="text: display"></td><td > </td>
<td> </td>
<td>
<input type="checkbox" data-bind="checked: $root.duplicates.indexOf(name1) !== -1" />
</td>
</tr>
</tbody>
My view model as below
var data1 = [{
name1: "one",
id: 1,
display: "Test1"
}, {
name1: "two",
id: 2,
display: "Test2"
}, {
name1: "three",
id: 3,
display: "Test3"
}];
var data2 = [{
name2: "five"
}, {
name2: "two"
}, {
name2: "three"
}];
var viewModel = {
dataOne: ko.observableArray(data1),
dataTwo: ko.observableArray(data2),
duplicates: ko.observableArray()
};
viewModel.dataTwo.push({
name: "four"
}); //add one on the end
var flattenedOne = ko.utils.arrayMap(viewModel.dataOne(), function (item) {
return item.name1;
});
var flattenedTwo = ko.utils.arrayMap(viewModel.dataTwo(), function (item) {
return item.name2;
});
var differences = ko.utils.compareArrays(flattenedOne, flattenedTwo);
//return a flat list of differences
ko.utils.arrayForEach(differences, function (difference) {
if (difference.status === 'retained') {
viewModel.duplicates.push(difference.value);
}
});
Now when user click on Update button it again load data and now 3 checkboxes are checked. What i am trying to achieve is
When user click on update button it should add css to table row and only make that row bold.
It should not check the checkbox as checked when user click's on update button.
So in our example when user click's on update button it should make row as bold but checkbox should not be checked. So only first row will be bold on clicking update button. Currently when page is loading it is making 2 rows bold and checked which is wrong. It should make row bold only clicking update button. Please help me guys.