Skip to content

Commit ca3ac94

Browse files
authored
Reset all filters on destroying a table or a card component (#109)
1 parent de4083a commit ca3ac94

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/ng-generate/components/card/generators/components/card/files/__name@dasherize__.component.ts.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit<% i
369369

370370
<% if (options.enableRemoteDataHandling || options.hasSearchBar ) { %>
371371
ngOnDestroy() {
372-
<% if (options.hasSearchBar) { %>
373-
this.filterService.searchString.setValue('');
372+
<% if (options.hasSearchBar || options.isEnumQuickFilter || options.isDateQuickFilter) { %>
373+
this.filterService.reset();
374374
<% } %>
375375

376376
this.destroy$.next();

src/ng-generate/components/shared/generators/services/filter/files/__name@dasherize__-filter.service.ts.template

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ export class <%= classify(name) %>FilterService {
174174
<% } %>
175175

176176
<% if (options.hasSearchBar || options.isEnumQuickFilter || options.isDateQuickFilter) { %>
177+
reset(): void {
178+
const appliedFilters = [...this.activeFilters];
179+
180+
appliedFilters.forEach((filter) => {
181+
this.resetFilter(filter)
182+
})
183+
}
184+
177185
/** Removes a specific filter. */
178186
removeFilter(filter:FilterType) {
179187
switch(filter.type) {

src/ng-generate/components/table/generators/components/table/files/__name@dasherize__.component.ts.template

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit, Af
307307

308308
<% if (options.hasSearchBar || options.enableRemoteDataHandling) { %>
309309
ngOnDestroy(): void {
310-
<% if (options.hasSearchBar) { %>this.filterService.searchString.setValue('');<% } %>
310+
<% if (options.hasSearchBar || options.isEnumQuickFilter || options.isDateQuickFilter) { %>
311+
this.filterService.reset();
312+
<% } %>
311313
this.ngUnsubscribe.next();
312314
this.ngUnsubscribe.complete();
313315
}

0 commit comments

Comments
 (0)