Friday, 25 December 2020

My date filter is not showing the results when I am selecting the same date in the start and end date. How to fix it?

I am using a custom filter pipe in angular. When I am selecting the same dates in the start date and end date it's not showing the result although the record is available for that date.

I need to enter 1 day before or earlier in the start date to see the result. Please suggest what changes do I need to make in my filter.

import { Pipe, PipeTransform } from "@angular/core";

@Pipe({
  name: "tableFilter"
})

export class TableFilterPipe implements PipeTransform {
  transform(list: any[], filters: any) {
    const keys = Object.keys(filters).filter(key => filters[key]);
    const filterUser = (user: { [x: string]: any; }) =>
      keys.every(key => {
        if (key == "sdob") {
          return new Date(user["dob"]) >= new Date(filters[key]);
        } else if (key == "edob") {
          return new Date(filters[key]) >= new Date(user["dob"]);
        } else {
          return user[key] === filters[key];
        }
      });
    return keys.length ? list.filter(filterUser) : list;
  }
}


from My date filter is not showing the results when I am selecting the same date in the start and end date. How to fix it?

No comments:

Post a Comment