Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. attendanceStatus:any;
  2. staffAttendanceList: StaffAttendance[] = [
  3. status:false,
  4. staff:{
  5. staffId:"ERP1001",
  6. firstName:'Rahul',
  7. lastName:'Sharma'
  8. }
  9. ];
  10.  
  11. 2)In HTML:
  12.  
  13. <input [(ngModel)]="searchStaffAttendance" type="text">
  14.  
  15. <table>
  16. <tbody>
  17. <tr*ngFor="let staffAttendance of staffAttendanceList|filter:searchStaffAttendance:'staff.staffId';
  18. index as i">
  19. <td>{{i+1}}</td>
  20. <td>{{staffAttendance.staff.staffId}}
  21. </td>
  22. <td>{{staffAttendance.staff.firstName}}
  23. {{staffAttendance.staff.lastName}}</td>
  24. </tr>
  25. </tbody>
  26. </table>
  27.  
  28. 3)In Filter pipe:
  29.  
  30. import { PipeTransform, Pipe } from "@angular/core";
  31.  
  32. @Pipe({
  33. name:'filter'
  34. })
  35. export class FilterPipe implements PipeTransform {
  36. transform = (value:[],filterString:any,propName:any):any => {
  37. let inputValue = [];
  38. if(filterString === undefined || filterString === '' ||
  39. value.length == 0){
  40. return value;
  41. }
  42. for(const item of value){
  43. if(item[propName] === filterString){
  44. inputValue.push(item);
  45. }
  46. }
  47. return inputValue;
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement