88 ViewEncapsulation
99} from '@angular/core' ;
1010
11- import { cloneDeep , defaults , isEqual } from 'lodash' ;
11+ import { cloneDeep , defaults , find , isEqual } from 'lodash' ;
1212
1313import { FilterConfig } from './filter-config' ;
1414import { FilterEvent } from './filter-event' ;
@@ -117,12 +117,24 @@ export class FilterFieldsComponent implements DoCheck, OnInit {
117117 if ( ! fieldFound ) {
118118 this . _currentField = this . config . fields [ 0 ] ;
119119 this . _currentValue = null ;
120+ } else if ( this . _currentField . type === 'select' || this . _currentField . type === 'typeahead' ) {
121+ // clear dropdown if there is no applied filter for it
122+ if ( ! this . getAppliedFilterByField ( this . _currentField ) ) {
123+ this . _currentValue = null ;
124+ }
120125 }
121126 if ( this . _currentValue === undefined ) {
122127 this . _currentValue = null ;
123128 }
124129 }
125130
131+ protected getAppliedFilterByField ( field : any ) : any {
132+ let foundFilter = find ( this . config . appliedFilters , {
133+ field : field
134+ } ) ;
135+ return foundFilter ;
136+ }
137+
126138 /**
127139 * Reset current field and value
128140 */
@@ -238,7 +250,13 @@ export class FilterFieldsComponent implements DoCheck, OnInit {
238250
239251 private selectField ( field : FilterField ) : void {
240252 this . _currentField = field ;
241- this . _currentValue = null ;
253+ if ( this . _currentField . type === 'select' || this . _currentField . type === 'typeahead' ) {
254+ // Restore selected value for dropdown if there is an applied filter for it
255+ let filterField : any = this . getAppliedFilterByField ( this . _currentField ) ;
256+ this . _currentValue = filterField ? filterField . value : null ;
257+ } else {
258+ this . _currentValue = null ;
259+ }
242260 this . onFieldSelect . emit ( {
243261 field : this . _currentField ,
244262 value : this . _currentValue
@@ -251,7 +269,7 @@ export class FilterFieldsComponent implements DoCheck, OnInit {
251269 query : filterQuery ,
252270 value : filterQuery . value
253271 } as FilterEvent ) ;
254- this . _currentValue = null ;
272+ this . _currentValue = filterQuery . value ;
255273 }
256274
257275 private showDelete ( ) : boolean {
0 commit comments