Skip to content

Commit

Permalink
Fixed #9879 - New Date Filters for Table
Browse files Browse the repository at this point in the history
  • Loading branch information
cagataycivici committed Feb 10, 2021
1 parent 8bff653 commit 7656b77
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/app/components/api/filtermatchmode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ export class FilterMatchMode {
public static readonly IS_NOT = 'isNot';
public static readonly BEFORE = 'before';
public static readonly AFTER = 'after';
public static readonly DATE_IS = 'dateIs';
public static readonly DATE_IS_NOT = 'dateIsNot';
public static readonly DATE_BEFORE = 'dateBefore';
public static readonly DATE_AFTER = 'dateAfter';
}
48 changes: 48 additions & 0 deletions src/app/components/api/filterservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,54 @@ export class FilterService {

after: (value, filter, filterLocale?): boolean => {
return this.filters.gt(value, filter, filterLocale);
},

dateIs: (value, filter): boolean => {
if (filter === undefined || filter === null) {
return true;
}

if (value === undefined || value === null) {
return false;
}

return value.toDateString() === filter.toDateString();
},

dateIsNot: (value, filter): boolean => {
if (filter === undefined || filter === null) {
return true;
}

if (value === undefined || value === null) {
return false;
}

return value.toDateString() !== filter.toDateString();
},

dateBefore: (value, filter): boolean => {
if (filter === undefined || filter === null) {
return true;
}

if (value === undefined || value === null) {
return false;
}

return value.getTime() < filter.getTime();
},

dateAfter: (value, filter): boolean => {
if (filter === undefined || filter === null) {
return true;
}

if (value === undefined || value === null) {
return false;
}

return value.getTime() > filter.getTime();
}

}
Expand Down
12 changes: 8 additions & 4 deletions src/app/components/api/primengconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export class PrimeNGConfig {
FilterMatchMode.GREATER_THAN_OR_EQUAL_TO
],
date: [
FilterMatchMode.IS,
FilterMatchMode.IS_NOT,
FilterMatchMode.BEFORE,
FilterMatchMode.AFTER
FilterMatchMode.DATE_IS,
FilterMatchMode.DATE_IS_NOT,
FilterMatchMode.DATE_BEFORE,
FilterMatchMode.DATE_AFTER
]
};

Expand All @@ -49,6 +49,10 @@ export class PrimeNGConfig {
isNot: 'Is not',
before: 'Before',
after: 'After',
dateIs: 'Date is',
dateIsNot: 'Date is not',
dateBefore: 'Date is before',
dateAfter: 'Date is after',
clear: 'Clear',
apply: 'Apply',
matchAll: 'Match All',
Expand Down
4 changes: 4 additions & 0 deletions src/app/components/api/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export interface Translation {
isNot?: string;
before?: string;
after?: string;
dateIs?: string;
dateIsNot?: string;
dateBefore?: string;
dateAfter?: string;
clear?: string;
apply?: string;
matchAll?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4378,7 +4378,7 @@ export class ColumnFilter implements AfterContentInit {
else if (this.type === 'numeric')
return FilterMatchMode.EQUALS;
else if (this.type === 'date')
return FilterMatchMode.EQUALS;
return FilterMatchMode.DATE_IS;
else
return FilterMatchMode.CONTAINS;
}
Expand Down

0 comments on commit 7656b77

Please sign in to comment.