HTML
<table>
<tr ng-repeat="checkbox in groupOfCheckboxes track by $index" ng-init="rowId = $index">
<td ng-repeat="data in checkbox.RowValues track by $index" ng-init="vId = $index">
<span ng-if="data.show" ng-click="setBinary(rowId,vId,data)"
ng-class="data.isActive ? 'active' : ''">{{data.td}}</span>
</td>
</tr>
</table>
Контроллер
$scope.groupOfCheckboxes = [
{
Row: "1",
RowValues: [
{ td: "1", show: true },
{ td: "2", show: true },
{ td: "3", show: true },
{ td: "4", show: true },
{ td: "5", show: true }
]
},
{
Row: "2",
RowValues: [
{ td: "6", show: false },
{ td: "7", show: false },
{ td: "8", show: false },
{ td: "9", show: true },
{ td: "10", show: false }
]
},
{
Row: "3",
RowValues: [
{ td: "11", show: false },
{ td: "12", show: false },
{ td: "13", show: true },
{ td: "14", show: true }
]
},
{
Row: "4",
RowValues: [
{ td: "15", show: false },
{ td: "16", show: false },
{ td: "17", show: false },
{ td: "18", show: true }
]
}
];
// Setting Parents
for (let rowIndex = $scope.groupOfCheckboxes.length - 1; rowIndex >= 0; rowIndex--) {
for (let valIndex = $scope.groupOfCheckboxes[rowIndex].RowValues.length - 1; valIndex >= 0; valIndex--) {
$scope.groupOfCheckboxes[rowIndex].RowValues[valIndex].isActive = false;
if ($scope.groupOfCheckboxes[rowIndex].RowValues[valIndex].show == true) {
loop4:
for (let rx = rowIndex; rx >= 0; rx--) {
for (let vx = valIndex - 1; vx >= 0; vx--) {
if ($scope.groupOfCheckboxes[rx].RowValues[vx].show == true) {
$scope.groupOfCheckboxes[rowIndex].RowValues[valIndex].pri = rx;
$scope.groupOfCheckboxes[rowIndex].RowValues[valIndex].pvi = vx;
break loop4;
};
}
}
};
}
}
$scope.setBinary = function (rowId, vId, data) {
data.isActive = !data.isActive
bool = data.isActive;
loopx:
for (let row = rowId; row < $scope.groupOfCheckboxes.length; row++) {
loop1:
for (let v = vId; v < $scope.groupOfCheckboxes[row].RowValues.length; v++) {
if (row == rowId) {
if ($scope.groupOfCheckboxes[row].RowValues[v].show == true) {
$scope.groupOfCheckboxes[row].RowValues[v].isActive = bool;
} else {
break;
};
} else {
if (v == vId) {
if ($scope.groupOfCheckboxes[row].RowValues[v].show == true) {
break loopx;
}
} else {
if ($scope.groupOfCheckboxes[row].RowValues[v].show == true) {
$scope.groupOfCheckboxes[row].RowValues[v].isActive = bool;
}
}
}
}
}
function rec(pri, pvi) {
if ($scope.groupOfCheckboxes[pri]) {
$scope.groupOfCheckboxes[pri].RowValues[pvi].isActive = true;
x = $scope.groupOfCheckboxes[pri].RowValues[pvi]
rec(x.pri, x.pvi)
}
}
rec(data.pri, data.pvi)
}