Функциональность поискового фильтра Angular4 для всей таблицы - PullRequest
0 голосов
/ 12 июня 2018

Здесь я реализовал небольшой фильтр поиска для таблицы, но мое требование заключается в том, должен ли он выполнять поиск по всей таблице, а не на странице?

search

<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 голосов
/ 12 июня 2018

Вы можете попробовать это решение

Я создал демо на 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'
}]
...