0
I created a table with Ngfor (actually, my whole project uses ngFor structures as default), I saw that there is an Ngrepeat and there is a filter for it. In order to avoid migrating my ngFor project, there is some way to filter my table?
I would use a text field and the entered value would be filtered (can be either by specific field or generalist)
I have tried using Pipetransform, but without success.
Html:
<div>
<table class="table table-striped">
<thead>
<tr>
<th scope = "col">PID </th>
<th scope = "col">CODIGO </th>
<th scope = "col">CLIENTE </th>
<th scope = "col">SIGLA_RM </th>
<th scope = "col">SIGLA_PORTAL </th>
<th scope = "col">COMERCIAL </th>
<th scope = "col">ATENDIMENTO </th>
<th scope = "col">AUDITORIA </th>
<th scope = "col">PERIODICIDADE </th>
<th scope = "col">ENTREGA </th>
<th scope = "col">RESPONSAVEL </th>
<th scope = "col">Comando </th>
</tr>
</thead>
<tbody>
<tr *ngFor = 'let planilha of planilha '>
<td>
{{planilha.ID}}
</td>
<td>
{{planilha.CODIGO}}
</td>
<td>
{{planilha.CLIENTE}}
</td>
<td>
{{planilha.SIGLA_RM}}
</td>
<td>
{{planilha.SIGLA_PORTAL}}
</td>
<td>
{{planilha.AUDITORIA}}
</td>
<td>
{{planilha.PERIODICIDADE}}
</td>
<td>
{{planilha.ENTREGA}}
</td>
<td>
{{planilha.RESPONSAVEL}}
</td>
<td>
{{planilha.LAYOUT}}
</td>
<td>
{{planilha.ODS}}
</td>
<td scope = "col">
<img src="assets/Detalhes.png" [routerLink]="['/detalhes/',planilha.PID]" width="25px"/>
<img src="assets/excluir.png" (click)="deletaProd(planilha.PID)" width="25px"/>
</td>
</tr>
</tbody>
</table>
</div>
Typescript:
import { Component, OnInit,Input, OnDestroy } from '@angular/core';
@Component({
selector: 'app-planilhaweb',
templateUrl: './planilhaweb.component.html',
styleUrls: ['./planilhaweb.component.css']
})
export class PlanilhawebComponent implements OnInit, OnDestroy {
@Input('planilha') public planilha
public xmlHttp = new XMLHttpRequest();
public detalhes: boolean = true
public detalhesId: number
constructor() {
this.dao();
}
ngOnDestroy(){
}
ngOnInit() {
}
public deletaProd(id){
function reqListener () {
console.log('tentou excluir ',id)
};
var oReq = new XMLHttpRequest();
oReq.onload = reqListener;
oReq.open("DELETE", "http://localhost:51230/api/logs/deletar/plan/"+id+"", true);
oReq.send();
this.dao();
this.load();
}
public detalhesProd(id){
this.detalhesId = id;
this.detalhes = !this.detalhes;
console.log(this.detalhesId)
}
dao(){
//CONEXAO COM A API
async function getPlanilha()
{
const response = await fetch(`http://localhost:51230/api/logs/producao/plan/`);
return await response.json();
}
//promisses
getPlanilha()
.then((planilha) => this.planilha = planilha)
}
load() {
//Session storage salva os dados como string
(sessionStorage.refresh == 'true' || !sessionStorage.refresh) && location.reload();
sessionStorage.refresh = true;
}
}
Updating:
I was able to filter my vector (json), but the table does not change dynamically by following the filter, as this should be done?
I was able to filter, however, how do I change the display according to the returned json? I’m having trouble fitting you into my asynchronous call. Thank you very much!
– Franco Genaro
@Francogenaro edited the answer and added this resolution for what I understood of your question.
– Gabryel Ferreira
@Gabriel Ferreira, I added an issue, I think I expressed myself badly. Everything’s already going according to plan except the animation, I’m having a hard time finding content on that. I tried your code but it brought me a mistake: Can’t bind to 'ngModel' Since it isn’t a known Property of 'input'. ("<div> <input type="text" [ERROR ->][(ngModel)]="filter" (ngModelChange)='filter(filter)'> <table class="table table-Striped">
– Franco Genaro
@Francogenaro this answer should help you: https://stackoverflow.com/questions/38892771/cant-bind-to-ngmodel-since-it-isnt-a-known-property-of-input
– Gabryel Ferreira
Not much ;( has no form on this page and nothing that behaves like a form that would doubt the link. I would need my TR to track my JSON changes, probably some change in ngfor...
– Franco Genaro
I say on the issue of ngModel error, what is missing is just an import in your app.component.ts. In the link I gave you he says that. Otherwise just follow what I’ve given you that will probably work.
– Gabryel Ferreira