Skip to content

Instantly share code, notes, and snippets.

@Sutil
Created October 22, 2020 23:48
Show Gist options
  • Save Sutil/fda7b3af25cbe52efc4fa873dc5be3ef to your computer and use it in GitHub Desktop.
Save Sutil/fda7b3af25cbe52efc4fa873dc5be3ef to your computer and use it in GitHub Desktop.
<table>
<thead>
<tr>
<!-- percorrer cada coluna -->
<th *ngFor="let coluna of colunas" class="{{ coluna.classeCssCabecalho }}" >
{{ coluna.cabecalho }}
</th>
</tr>
</thead>
<tbody>
<!-- percorrer cada linha -->
<ng-container *ngFor="let linha of linhas">
<!-- Em breve iremos criar o componente que representa cada linha -->
<linha-tabela-aninhada
[linha]="linha"
[colunas]="colunas"
[extratorDeFilhos]="extratorDeFilhos"
[extratorDeClasseCss]="extratorDeClasseCss" ></linha-tabela-aninhada>
</ng-container>
</tbody>
</table>
table {
width: 100%;
border-spacing: 0;
}
td {
border-top: 1px solid white;
}
import { Component, Input, OnInit } from '@angular/core';
import { ColunaTabelaAninhada } from './coluna-tabela-aninhada';
@Component({
selector: 'tabela-aninhada',
templateUrl: './tabela-aninhada.component.html',
styleUrls: ['./tabela-aninhada.component.scss']
})
export class TabelaAninhadaComponent {
/**
* Informe as colunas da sua tabelas
*/
@Input()
colunas: ColunaTabelaAninhada[] = [];
/**
* Informe o array de dados da sua tabela, onde cada elemento será um linhas da tabela
*/
@Input()
linhas: any[] = [];
/**
* Informe a função para extrair, de cada linha, as linhas filhas.
*/
@Input()
extratorDeFilhos: (linha: any) => any[] = (_:any) => null;
/**
* Informe a função para extrair, de cada linha, a classe de css customizada
*/
@Input()
extratorDeClasseCss: (nivel) => string;
constructor() { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment