We have this directive which receives a dictionary.
We were thinking that a directivy would be able of calling itself recursively, but it is not working.
Our current data structure is:
var cubicApp = angular.module('CubicApp', ['autocomplete']).controller('PreviewForecastCtrl', function ($scope, $http) {
$scope.name = 'Thiago';
$scope.performance = {
headers: [{ name: '', colspan: 1 }, { name: 'Week result', colspan: 6 }, { name: '2017', colspan: 13 }, { name: 'General', colspan: 4 }],
subheaders: [
{ name: 'Product', colspan: 1 },
{ name: '29-May', colspan: 1 },
{ name: '30-May', colspan: 1 },
{ name: '31-May', colspan: 1 },
{ name: '01-Jun', colspan: 1 },
{ name: '02-Jun', colspan: 1 },
{ name: 'Total', colspan: 1 },
{ name: 'Jan', colspan: 1 },
{ name: 'Feb', colspan: 1 },
{ name: 'Mar', colspan: 1 },
{ name: 'Apr', colspan: 1 },
{ name: 'May', colspan: 1 },
{ name: 'Jun', colspan: 1 },
{ name: 'Jul', colspan: 1 },
{ name: 'Aug', colspan: 1 },
{ name: 'Sep', colspan: 1 },
{ name: 'Oct', colspan: 1 },
{ name: 'Nov', colspan: 1 },
{ name: 'Dec', colspan: 1 },
{ name: 'Year', colspan: 1 },
{ name: '1M', colspan: 1 },
{ name: '6M', colspan: 1 },
{ name: '12M', colspan: 1 },
{ name: 'Accum.', colspan: 1 }
],
books: [
{
name: 'Renda Variável',
css: 'primary',
totals: Array.from({length: 23}, () => Math.random()),
books: [
{
name: 'Ibovespa Ativo',
css: 'active',
totals: Array.from({ length: 23 }, () => Math.random()),
books: [
{
name: 'BOVA11 (Equity)',
css: '',
totals: Array.from({ length: 23 }, () => Math.random()),
books: []
},
{
name: 'Cash BRL (Cash)',
css: '',
totals: Array.from({ length: 23 }, () => Math.random()),
books: []
}
]
}
]
}
]
};
$scope.loadInfo = function () {
};
});
The directives are:
cubicApp.directive('drillDownTable', function ($document) {
return {
restrict: 'E',
transclude: true,
scope: {
data: '=',
},
templateUrl: '../../Scripts/app/templates/drill-down-table.html'
};
}).directive('inner', function ($document, $compile) {
return {
restrict: 'A',
transclude: true,
scope: {
inner: '=',
},
templateUrl: '../../Scripts/app/templates/drill-down-inner-table.html'
};
});;
drill-down-table.html
:
<table class="table table-hover table-bordered jambo_table">
<thead>
<tr>
<th ng-repeat="h in data.headers" colspan="{{h.colspan}}" style="text-align:center !important">{{h.name}}</th>
</tr>
<tr>
<th ng-repeat="h in data.subheaders" colspan="{{h.colspan}}" style="text-align:center !important">{{h.name}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="book in data.books" inner="book"></tr>
</tbody>
</table>
drill-down-inner-table.html
:
<tr>
<td>{{inner.name}}</td>
<td ng-repeat="t in inner.totals">{{t | number : 2}}</td>
</tr>
<tr ng-repeat="book in inner.books" inner="book"></tr>