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,6 +10,9 @@ export abstract class StatementBase implements AfterViewInit, OnInit { | ||
10 | protected gridOptions: GridOptions; | 10 | protected gridOptions: GridOptions; |
11 | protected service: StatementBaseService; | 11 | protected service: StatementBaseService; |
12 | protected loadingService: TdLoadingService; | 12 | protected loadingService: TdLoadingService; |
13 | + protected paramsSubject: Subject<IGetRowsParams> = new Subject<IGetRowsParams>(); | ||
14 | + protected params: IGetRowsParams; | ||
15 | + protected data: Observable<any[]>; | ||
13 | public showGrid: boolean; | 16 | public showGrid: boolean; |
14 | public rowCount: string; | 17 | public rowCount: string; |
15 | public isLoading: boolean = false; | 18 | public isLoading: boolean = false; |
@@ -24,6 +27,24 @@ export abstract class StatementBase implements AfterViewInit, OnInit { | @@ -24,6 +27,24 @@ export abstract class StatementBase implements AfterViewInit, OnInit { | ||
24 | 27 | ||
25 | ngAfterViewInit(): void { | 28 | ngAfterViewInit(): void { |
26 | this.gridOptions.api.setDatasource(this.setRowData()); | 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 | enableLoader(): void { | 50 | enableLoader(): void { |
@@ -91,16 +112,18 @@ export abstract class StatementBase implements AfterViewInit, OnInit { | @@ -91,16 +112,18 @@ export abstract class StatementBase implements AfterViewInit, OnInit { | ||
91 | let dataSource: {} = { | 112 | let dataSource: {} = { |
92 | rowCount: null, | 113 | rowCount: null, |
93 | getRows: (params: IGetRowsParams) => { | 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 | return dataSource; | 129 | return dataSource; |
@@ -142,7 +165,8 @@ export abstract class StatementBase implements AfterViewInit, OnInit { | @@ -142,7 +165,8 @@ export abstract class StatementBase implements AfterViewInit, OnInit { | ||
142 | } | 165 | } |
143 | this.enableLoader(); | 166 | this.enableLoader(); |
144 | result = this.service.create(data).then((model: any) => { | 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 | this.disableLoader(); | 170 | this.disableLoader(); |
147 | this.isNew = false; | 171 | this.isNew = false; |
148 | }); | 172 | }); |
@@ -163,7 +187,8 @@ export abstract class StatementBase implements AfterViewInit, OnInit { | @@ -163,7 +187,8 @@ export abstract class StatementBase implements AfterViewInit, OnInit { | ||
163 | this.service.delete(id).then(() => { | 187 | this.service.delete(id).then(() => { |
164 | if (index === (array.length - 1)) { | 188 | if (index === (array.length - 1)) { |
165 | this.disableLoader(); | 189 | this.disableLoader(); |
166 | - this.gridOptions.api.setDatasource(this.setRowData()); | 190 | + this.gridOptions.api.refreshVirtualPageCache(); |
191 | + // this.gridOptions.api.setDatasource(this.setRowData()); | ||
167 | this.gridOptions.api.deselectAll(); | 192 | this.gridOptions.api.deselectAll(); |
168 | this.isNew = false; | 193 | this.isNew = false; |
169 | } | 194 | } |
src/services/statement.base.service.ts
@@ -93,13 +93,13 @@ export abstract class StatementBaseService { | @@ -93,13 +93,13 @@ export abstract class StatementBaseService { | ||
93 | case 'equals': | 93 | case 'equals': |
94 | symbol = '='; | 94 | symbol = '='; |
95 | break; | 95 | break; |
96 | - case 'not equals': | 96 | + case 'notEquals': |
97 | symbol = '!'; | 97 | symbol = '!'; |
98 | break; | 98 | break; |
99 | - case 'starts with': | 99 | + case 'startsWith': |
100 | symbol = '^'; | 100 | symbol = '^'; |
101 | break; | 101 | break; |
102 | - case 'ends with': | 102 | + case 'endsWith': |
103 | symbol = '$'; | 103 | symbol = '$'; |
104 | break; | 104 | break; |
105 | default: | 105 | default: |