整个表

时间:2018-06-12 10:17:36

标签: angular angular2-forms angular4-forms angular2-filtering

这里我实现了一个表上的小搜索过滤器但是我的要求是它应该搜索整个表不在页面内吗?

搜索

<label> Search FRom Table:</label> <input (change)="someval($event.target.value)">          


someval(value){
   let data=JSON.stringify(value);
   console.log(data.length);
   this.auction.find(e=>e.uniqueid=data);
   this.GetDashBoardData();
}
GetDashBoardData(){
    var somedata= this.globalService.getBasicInfoData();
    this.auctionRequest = {    
      "loginId": this.userdata.LoginID
    }; 
    return this.httpService.dashbordTheUser2(this.auctionRequest).subscribe((response) => {
      this.auction = response.data;
}

在这里,我稍微改变一下,当我在文本框中输入一些文本时,它在 This.auction 的数组中,但我不知道如何在表中绑定它

<tr *ngFor="let value of pagedItems">
                     <td>{{value.name}}</td>

1 个答案:

答案 0 :(得分:3)

你可以试试这个解决方案

我在stackblitz

上创建了一个演示
  

搜索管道

transform(value: any, args?: any): any {
    if (!args) {
      return value;
    }
    return value.filter((val) => {
      let rVal = (val.id.toLocaleLowerCase().includes(args)) || (val.email.toLocaleLowerCase().includes(args));
      return rVal;
    })

}
  

html代码

<tr *ngFor="let customer of users | customerEmailFilter:email;let i = index">
    <th scope="row">{{i+1}}</th>
    <td>{{customer.id}}</td>
    <td>{{customer.email}}</td>
</tr>
  

ts文件代码

users=[{
    id:'123',
    email:'abc@gmail.com'
  },{
    id:'1234',
    email:'xyz@hotmail.com'
  },{
    id:'12345',
    email:'jsgsbh@kk.com'
  },{
    id:'123456',
    email:'test@gmail.com'
}]