Commit fb475cb77f3b6d5acee18d6b82671125c52ce412
1 parent
f0f55555
Observable
Showing
2 changed files
with
40 additions
and
15 deletions
Show diff stats
src/models/statement.base.ts
| ... | ... | @@ -10,6 +10,9 @@ export abstract class StatementBase implements AfterViewInit, OnInit { |
| 10 | 10 | protected gridOptions: GridOptions; |
| 11 | 11 | protected service: StatementBaseService; |
| 12 | 12 | protected loadingService: TdLoadingService; |
| 13 | + protected paramsSubject: Subject<IGetRowsParams> = new Subject<IGetRowsParams>(); | |
| 14 | + protected params: IGetRowsParams; | |
| 15 | + protected data: Observable<any[]>; | |
| 13 | 16 | public showGrid: boolean; |
| 14 | 17 | public rowCount: string; |
| 15 | 18 | public isLoading: boolean = false; |
| ... | ... | @@ -24,6 +27,24 @@ export abstract class StatementBase implements AfterViewInit, OnInit { |
| 24 | 27 | |
| 25 | 28 | ngAfterViewInit(): void { |
| 26 | 29 | this.gridOptions.api.setDatasource(this.setRowData()); |
| 30 | + this.data = this.paramsSubject | |
| 31 | + .distinctUntilChanged() | |
| 32 | + .switchMap((params: IGetRowsParams) => { | |
| 33 | + return this.service.getData(params); | |
| 34 | + }).catch((error: any) => { | |
| 35 | + console.log(error); | |
| 36 | + return Observable.of<any[]>([]); | |
| 37 | + }); | |
| 38 | + this.data.subscribe((data: any[]) => { | |
| 39 | + if (!data.length) { | |
| 40 | + data = [this.createModel()]; | |
| 41 | + } | |
| 42 | + let lastRow: number = -1; | |
| 43 | + if (data.length <= this.params.endRow) { | |
| 44 | + lastRow = data.length; | |
| 45 | + } | |
| 46 | + this.params.successCallback(data, lastRow); | |
| 47 | + }); | |
| 27 | 48 | } |
| 28 | 49 | |
| 29 | 50 | enableLoader(): void { |
| ... | ... | @@ -91,16 +112,18 @@ export abstract class StatementBase implements AfterViewInit, OnInit { |
| 91 | 112 | let dataSource: {} = { |
| 92 | 113 | rowCount: null, |
| 93 | 114 | getRows: (params: IGetRowsParams) => { |
| 94 | - this.service.getData(params).subscribe((data: any[]) => { | |
| 95 | - if (!data.length) { | |
| 96 | - data = [this.createModel()]; | |
| 97 | - } | |
| 98 | - let lastRow: number = -1; | |
| 99 | - if (data.length <= params.endRow) { | |
| 100 | - lastRow = data.length; | |
| 101 | - } | |
| 102 | - params.successCallback(data, lastRow); | |
| 103 | - }); | |
| 115 | + this.params = params; | |
| 116 | + this.paramsSubject.next(params); | |
| 117 | + // this.service.getData(params).subscribe((data: any[]) => { | |
| 118 | + // if (!data.length) { | |
| 119 | + // data = [this.createModel()]; | |
| 120 | + // } | |
| 121 | + // let lastRow: number = -1; | |
| 122 | + // if (data.length <= params.endRow) { | |
| 123 | + // lastRow = data.length; | |
| 124 | + // } | |
| 125 | + // params.successCallback(data, lastRow); | |
| 126 | + // }); | |
| 104 | 127 | }, |
| 105 | 128 | }; |
| 106 | 129 | return dataSource; |
| ... | ... | @@ -142,7 +165,8 @@ export abstract class StatementBase implements AfterViewInit, OnInit { |
| 142 | 165 | } |
| 143 | 166 | this.enableLoader(); |
| 144 | 167 | result = this.service.create(data).then((model: any) => { |
| 145 | - this.gridOptions.api.setDatasource(this.setRowData()); | |
| 168 | + this.gridOptions.api.refreshVirtualPageCache(); | |
| 169 | + // this.gridOptions.api.setDatasource(this.setRowData()); | |
| 146 | 170 | this.disableLoader(); |
| 147 | 171 | this.isNew = false; |
| 148 | 172 | }); |
| ... | ... | @@ -163,7 +187,8 @@ export abstract class StatementBase implements AfterViewInit, OnInit { |
| 163 | 187 | this.service.delete(id).then(() => { |
| 164 | 188 | if (index === (array.length - 1)) { |
| 165 | 189 | this.disableLoader(); |
| 166 | - this.gridOptions.api.setDatasource(this.setRowData()); | |
| 190 | + this.gridOptions.api.refreshVirtualPageCache(); | |
| 191 | + // this.gridOptions.api.setDatasource(this.setRowData()); | |
| 167 | 192 | this.gridOptions.api.deselectAll(); |
| 168 | 193 | this.isNew = false; |
| 169 | 194 | } | ... | ... |
src/services/statement.base.service.ts
| ... | ... | @@ -93,13 +93,13 @@ export abstract class StatementBaseService { |
| 93 | 93 | case 'equals': |
| 94 | 94 | symbol = '='; |
| 95 | 95 | break; |
| 96 | - case 'not equals': | |
| 96 | + case 'notEquals': | |
| 97 | 97 | symbol = '!'; |
| 98 | 98 | break; |
| 99 | - case 'starts with': | |
| 99 | + case 'startsWith': | |
| 100 | 100 | symbol = '^'; |
| 101 | 101 | break; |
| 102 | - case 'ends with': | |
| 102 | + case 'endsWith': | |
| 103 | 103 | symbol = '$'; |
| 104 | 104 | break; |
| 105 | 105 | default: | ... | ... |