Angular: Multiple Tables with level3 ng-collapse
AngularJS 1.5.0 (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js)
Bootstrap (https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css)
UI Bootstrap (https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/1.1.2/ui-bootstrap-tpls.min.js)
HTML
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/1.1.2/ui-bootstrap-tpls.min.js"></script>
<div ng-app="myApp">
<div ng-controller="myController" class="row-fluid span12">
<!-- START $scope.[model] updates -->
<div class="span12 well well-small">
<div class="span5">
<p class="nav-header">collapse/expand tableRow</p>
<p class="small-caps">tableRowExpanded: <b>{{tableRowExpanded}}</b>
</p>
<p class="small-caps">tableRowIndexCurrExpanded: <b>{{tableRowIndexCurrExpanded}}</b>a
</p>
<p class="small-caps">storeIdExpanded: <b>{{storeIdExpanded}}</b>
</p>
</div>
<div class="span7">
<p class="nav-header">dayDataCollapse</p>{{dayDataCollapse}}</div>
</div>
<!-- END $scope.[model] updates -->
<!-- START TABLE -->
<div>
<table class="table table-hover table-condensed table-striped">
<thead>
<tr>
<th>Store ID</th>
<th>Name</th>
<th>Address</th>
<th>City</th>
<th>Cost</th>
<th>Sales</th>
<th>Revenue</th>
<th>Employees</th>
<th>Employees H-sum</th>
</tr>
</thead>
<tbody data-ng-repeat="storedata in storeDataModel.storedata">
...
CSS
body {
padding: 10px;
padding-right:30px;
}
table {
border-collapse: separate;
border-spacing: 0 5px;
padding: 0px;
}
thead th {
background-color: #006DCC;
color: white;
}
tbody td {
<!-- background-color: #EEEEEE;
-->
}
tr td:first-child, tr th:first-child {
border-top-left-radius: 6px;
border-bottom-left-radius: 6px;
}
tr td:last-child, tr th:last-child {
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
}
.clickableRow {
cursor: pointer;
}
p, textarea {
font-variant: small-caps !important;
text-rendering: auto;
}
td, th {
font-size: 8pt;
}
table {
padding: 0px;
}
JavaScript
var myApp = angular.module('myApp', ['ui.bootstrap']);
myApp.controller('myController', function ($scope) {
$scope.tableRowExpanded = false;
$scope.tableRowIndexCurrExpanded = "";
$scope.tableRowIndexPrevExpanded = "";
$scope.storeIdExpanded = "";
$scope.dayDataCollapse = [true, true, true, true, true, true];
$scope.transactionShow = 0;
$scope.dayDataCollapseFn = function () {
for (var i = 0; $scope.storeDataModel.storedata.length - 1; i += 1) {
$scope.dayDataCollapse.append('true');
}
};
$scope.selectTableRow = function (index, storeId) {
if ($scope.dayDataCollapse === 'undefined') {
$scope.dayDataCollapse = $scope.dayDataCollapseFn();
} else {
if ($scope.tableRowExpanded === false && $scope.tableRowIndexCurrExpanded === "" && $scope.storeIdExpanded === "") {
$scope.tableRowIndexPrevExpanded = "";
$scope.tableRowExpanded = true;
$scope.tableRowIndexCurrExpanded = index;
$scope.storeIdExpanded = storeId;
$scope.dayDataCollapse[index] = false;
} else if ($scope.tableRowExpanded === true) {
if ($scope.tableRowIndexCurrExpanded === index && $scope.storeIdExpanded === storeId) {
$scope.tableRowExpanded = false;
$scope.tableRowIndexCurrExpanded = "";
$scope.storeIdExpanded = "";
$scope.dayDataCollapse[index] = true;
} else {
$scope.tableRowIndexPrevExpanded = $scope.tableRowIndexCurrExpanded;
$scope.tableRowIndexCurrExpanded = index;
$scope.storeIdExpanded = storeId;
$scope.dayDataCollapse[$scope.tableRowIndexPrevExpanded] = true;
$scope.dayDataCollapse[$scope.tableRowIndexCurrExpanded] = false;
}
}
}
};
...