From 363b349cca0673bf9e6393d946b6956de664eeaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fatay=20=C3=87ivici?= Date: Wed, 16 Nov 2016 16:48:16 +0300 Subject: [PATCH] Fixed #1295 --- components/datatable/datatable.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/components/datatable/datatable.ts b/components/datatable/datatable.ts index 80d6b292b40..185843ad3e3 100644 --- a/components/datatable/datatable.ts +++ b/components/datatable/datatable.ts @@ -455,6 +455,8 @@ export class DataTable implements AfterViewChecked,AfterViewInit,AfterContentIni public rowTouch: boolean; public editingCell: any; + + public filteredByUser: boolean; differ: any; @@ -463,7 +465,7 @@ export class DataTable implements AfterViewChecked,AfterViewInit,AfterContentIni preventBlurOnEdit: boolean; columnsSubscription: Subscription; - + constructor(public el: ElementRef, public domHandler: DomHandler, differs: IterableDiffers, public renderer: Renderer, private changeDetector: ChangeDetectorRef) { this.differ = differs.find([]).create(null); @@ -541,6 +543,13 @@ export class DataTable implements AfterViewChecked,AfterViewInit,AfterContentIni this.updatePaginator(); } + if(this.hasFilter()) { + if(this.filteredByUser) + this.filteredByUser = false; + else + this.filter(); + } + if(this.stopSortPropagation) { this.stopSortPropagation = false; } @@ -993,9 +1002,14 @@ export class DataTable implements AfterViewChecked,AfterViewInit,AfterContentIni } this.filterTimeout = setTimeout(() => { - this.filters[field] = {value: value, matchMode: matchMode}; + if(value && value.trim().length) + this.filters[field] = {value: value, matchMode: matchMode}; + else if(this.filters[field]) + delete this.filters[field]; + + this.filteredByUser = true; this.filter(); - this.filterTimeout = null; + this.filterTimeout = null; }, this.filterDelay); }