From f5ea037a88c12d8a339ed54b6ee32fc1960d0f0a Mon Sep 17 00:00:00 2001 From: Yubing325 <35515298+Yubing325@users.noreply.github.com> Date: Thu, 2 Jul 2020 10:16:13 -0500 Subject: [PATCH] ng-select basic done --- .../ng-select/ng-select.component.html | 2 +- .../ng-select/ng-select.component.ts | 39 +++++++++++++------ .../ng-select-demo.component.html | 5 +-- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/projects/poweredsoft/ngx-cdk-ui/src/lib/ps-selectors/ng-select/ng-select.component.html b/projects/poweredsoft/ngx-cdk-ui/src/lib/ps-selectors/ng-select/ng-select.component.html index 3002f81..2423cae 100644 --- a/projects/poweredsoft/ngx-cdk-ui/src/lib/ps-selectors/ng-select/ng-select.component.html +++ b/projects/poweredsoft/ngx-cdk-ui/src/lib/ps-selectors/ng-select/ng-select.component.html @@ -1,5 +1,5 @@ ; + @Input() searchPath: string; + @Input() searchType: string = "Contains"; + @Input() sortingPath: string; + @Input() disableServer:boolean = false; + + @Input() bindLabel:string; + data$ : Observable; selectedId:any; isLoading:boolean = false; searchInput$ = new Subject(); + private _dataSubscription: Subscription; + constructor(private cdr: ChangeDetectorRef) { } + ngOnDestroy(): void { + this._dataSubscription.unsubscribe(); + } ngOnInit(): void { this.dataFetching(); this.detectLoading(); - this.searchOnServer(); + if(!this.disableServer){ + this.searchOnServer(); + }else{ + this.refreshDataSource(); + } } @@ -34,6 +50,7 @@ export class NgSelectComponent implements OnInit { return t.data; }) ); + this._dataSubscription = this.dataSource.data$.subscribe(); } detectLoading(){ @@ -47,26 +64,26 @@ export class NgSelectComponent implements OnInit { this.searchInput$.pipe( distinctUntilChanged(), // emit the difference from previous input debounceTime(500) // this is for delaying searching speed - ).subscribe(searchTerm => this.refreshDataSource(searchTerm)); + ).subscribe(searchTerm => this.refreshDataSource(searchTerm, 1, 50)); // page: 1, pageSize: 50 this.refreshDataSource(); //send the query to server to sorting & filtering by default } - refreshDataSource(searchTerm:any = null){ + refreshDataSource(searchTerm:any = null, page:number=null, pageSize:number=null){ let searchfilters:ISimpleFilter[] = null; if(searchTerm){ searchfilters = [{ - path: 'name', //Todo: add input variable for this filtering path - type: 'startsWith',//Todo: add input variable for this type, could be contains, startsWith, endswith, equal + path: this.searchPath, + type: this.searchType, // Default: Contains value: searchTerm }] } this.dataSource.query({ - page: 1, - pageSize: 50, + page: page, + pageSize: pageSize, filters:searchfilters, sorts:[ - {path: 'name', ascending: true} //Todo: add input variable for sorting path + {path: this.sortingPath, ascending: true} ] }) } diff --git a/src/app/ng-select-demo/ng-select-demo/ng-select-demo.component.html b/src/app/ng-select-demo/ng-select-demo/ng-select-demo.component.html index 7a28c9c..f49b018 100644 --- a/src/app/ng-select-demo/ng-select-demo/ng-select-demo.component.html +++ b/src/app/ng-select-demo/ng-select-demo/ng-select-demo.component.html @@ -1,4 +1 @@ - - - - \ No newline at end of file + \ No newline at end of file