Skip to content

Instantly share code, notes, and snippets.

@guiseek
Created March 29, 2020 23:04
Show Gist options
  • Save guiseek/1613abe7f43f43f196ea302d486307f7 to your computer and use it in GitHub Desktop.
Save guiseek/1613abe7f43f43f196ea302d486307f7 to your computer and use it in GitHub Desktop.
// Função
export const addColumn = <T = any>(prop: string) => {
const shift = prop.split('.').pop();
return (payload: T): T => {
const column = prop.split('.')
.reduce((p, c) => payload[p][c]);
return ({ ...payload, [shift]: column });
}
}
<!-- Facilita o search usando DataSource filter -->
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef mat-sort-header>Nome</mat-header-cell>
<mat-cell *matCellDef="let row">
<span class="text-truncate">{{ row.name }}</span>
</mat-cell>
</ng-container>
// Exemplo de uso
this.service
.findEvaluations()
.valueChanges()
.pipe(
takeUntil(this.destroy$),
map(d => d.map(addColumn('patient.name')))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment