Commit 4384eb9b38e97f301415784f001f13fddfda3033
1 parent
5c070939
Shit
Showing
2 changed files
with
75 additions
and
27 deletions
Show diff stats
src/app/pages/statements/components/busStop2/busStop2.component.ts
@@ -25,7 +25,7 @@ export class BusStop2 { | @@ -25,7 +25,7 @@ export class BusStop2 { | ||
25 | // source: LocalDataSource = new LocalDataSource(); | 25 | // source: LocalDataSource = new LocalDataSource(); |
26 | 26 | ||
27 | public showGrid: boolean; | 27 | public showGrid: boolean; |
28 | - public rowData: any[]; | 28 | + public rowData: any[] = []; |
29 | public rowCount: string; | 29 | public rowCount: string; |
30 | public regions: RegionSelectList[]; | 30 | public regions: RegionSelectList[]; |
31 | public states: StateCommonSelectList[]; | 31 | public states: StateCommonSelectList[]; |
@@ -40,26 +40,43 @@ export class BusStop2 { | @@ -40,26 +40,43 @@ export class BusStop2 { | ||
40 | protected service: BusStop2Service, | 40 | protected service: BusStop2Service, |
41 | private dataService: BusStopCreateService, | 41 | private dataService: BusStopCreateService, |
42 | ) { | 42 | ) { |
43 | + this.gridOptions = <GridOptions>{}; | ||
44 | + this.gridOptions.rowModelType = 'virtual'; | ||
45 | + this.showGrid = true; | ||
46 | + let dataSource = { | ||
47 | + rowCount: null, // behave as infinite scroll | ||
48 | + getRows: function (params) { | ||
49 | + // At this point in your code, you would call the server, using $http if in AngularJS. | ||
50 | + // To make the demo look real, wait for 500ms before returning | ||
51 | + // take a slice of the total rows | ||
52 | + let rowsThisPage = this.rowData.slice(params.startRow, params.endRow); | ||
53 | + // if on or after the last page, work out the last row. | ||
54 | + let lastRow = -1; | ||
55 | + if (this.rowData.length <= params.endRow) { | ||
56 | + lastRow = this.rowData.length; | ||
57 | + } | ||
58 | + // call the success callback | ||
59 | + params.successCallback(rowsThisPage, lastRow); | ||
60 | + }.bind(this) | ||
61 | + }; | ||
62 | + this.gridOptions.datasource = dataSource; | ||
43 | this.dataService.getModels().then(models => { | 63 | this.dataService.getModels().then(models => { |
44 | this.regions = models.regionSelectListDsM as RegionSelectList[]; | 64 | this.regions = models.regionSelectListDsM as RegionSelectList[]; |
45 | this.states = models.stateCommonSelectListDsM as StateCommonSelectList[]; | 65 | this.states = models.stateCommonSelectListDsM as StateCommonSelectList[]; |
46 | this.surfaceTypes = models.surfaceTypeSelectListDsM as SurfaceTypeSelectList[]; | 66 | this.surfaceTypes = models.surfaceTypeSelectListDsM as SurfaceTypeSelectList[]; |
47 | this.settlements = models.settlementSelectListDsM as SettlementSelectList[]; | 67 | this.settlements = models.settlementSelectListDsM as SettlementSelectList[]; |
48 | this.roads = models.roadSelectListDsM as RoadSelectList[]; | 68 | this.roads = models.roadSelectListDsM as RoadSelectList[]; |
69 | + this.service.getData().then((data) => { | ||
70 | + if (data.length){ | ||
71 | + // this.source.load(data); | ||
72 | + this.rowData = data; | ||
73 | + } else { | ||
74 | + this.rowData = [new busStop2]; | ||
75 | + } | ||
49 | this.createColumnDefs(); | 76 | this.createColumnDefs(); |
77 | + this.gridOptions.api.refreshVirtualPageCache(); | ||
78 | + }); | ||
50 | }); | 79 | }); |
51 | - this.gridOptions = <GridOptions>{}; | ||
52 | - // this.gridOptions.rowModelType = 'virtual'; | ||
53 | - this.service.getData().then((data) => { | ||
54 | - console.log(data); | ||
55 | - if (data.length){ | ||
56 | - // this.source.load(data); | ||
57 | - this.rowData = data; | ||
58 | - } else { | ||
59 | - this.rowData = [new busStop2]; | ||
60 | - } | ||
61 | - }); | ||
62 | - this.showGrid = true; | ||
63 | } | 80 | } |
64 | 81 | ||
65 | onDeleteConfirm(event): void { | 82 | onDeleteConfirm(event): void { |
@@ -69,7 +86,31 @@ export class BusStop2 { | @@ -69,7 +86,31 @@ export class BusStop2 { | ||
69 | event.confirm.reject(); | 86 | event.confirm.reject(); |
70 | } | 87 | } |
71 | } | 88 | } |
72 | - | 89 | + public addNewRow() { |
90 | + this.rowData.unshift(new busStop2()); | ||
91 | + this.gridOptions.api.refreshVirtualPageCache(); | ||
92 | + } | ||
93 | + private setRowData(data) { | ||
94 | + let dataSource = { | ||
95 | + rowCount: null, // behave as infinite scroll | ||
96 | + getRows: function (params) { | ||
97 | + // At this point in your code, you would call the server, using $http if in AngularJS. | ||
98 | + // To make the demo look real, wait for 500ms before returning | ||
99 | + setTimeout( function() { | ||
100 | + // take a slice of the total rows | ||
101 | + var rowsThisPage = data.slice(params.startRow, params.endRow); | ||
102 | + // if on or after the last page, work out the last row. | ||
103 | + var lastRow = -1; | ||
104 | + if (data.length <= params.endRow) { | ||
105 | + lastRow = data.length; | ||
106 | + } | ||
107 | + // call the success callback | ||
108 | + params.successCallback(rowsThisPage, lastRow); | ||
109 | + }, 500); | ||
110 | + } | ||
111 | + }; | ||
112 | + this.gridOptions.datasource = dataSource; | ||
113 | + } | ||
73 | private createColumnDefs() { | 114 | private createColumnDefs() { |
74 | this.columnDefs = [ | 115 | this.columnDefs = [ |
75 | { | 116 | { |
src/app/pages/statements/components/busStop2/busStop2.service.ts
@@ -11,19 +11,26 @@ export class BusStop2Service { | @@ -11,19 +11,26 @@ export class BusStop2Service { | ||
11 | private headers = new Headers({'Content-Type': 'application/json'}); | 11 | private headers = new Headers({'Content-Type': 'application/json'}); |
12 | constructor(private http: Http) { } | 12 | constructor(private http: Http) { } |
13 | getData(): Promise<busStop2[]> { | 13 | getData(): Promise<busStop2[]> { |
14 | - // let busStops: BusStop2[] = [{ | ||
15 | - // id: 1, | ||
16 | - // road: 'Test', | ||
17 | - // region: 'Test', | ||
18 | - // locationLeft: '1', | ||
19 | - // locationRight: '1', | ||
20 | - // state: 'Test' | ||
21 | - // }]; | ||
22 | - // return Promise.resolve(busStops); | ||
23 | - return this.http.get(this.url) | ||
24 | - .toPromise() | ||
25 | - .then(response => response.json().busStopEditDsM as busStop2[]) | ||
26 | - .catch(this.handleError); | 14 | + let busStops: busStop2[] = [{ |
15 | + roadId: 1, | ||
16 | + regionId: 1, | ||
17 | + settlementId: 1, | ||
18 | + surfaceTypeId: '1', | ||
19 | + locationLeft: '1', | ||
20 | + locationRight: '1', | ||
21 | + stateCommonId: 1, | ||
22 | + areaStopAvailability: '', | ||
23 | + areaLandAvailability: '', | ||
24 | + pocketAvailability: '', | ||
25 | + toiletAvailability: '', | ||
26 | + yearBuild: '', | ||
27 | + yearRepair: '', | ||
28 | + }]; | ||
29 | + return Promise.resolve(busStops); | ||
30 | + // return this.http.get(this.url) | ||
31 | + // .toPromise() | ||
32 | + // .then(response => response.json().busStopEditDsM as busStop2[]) | ||
33 | + // .catch(this.handleError); | ||
27 | } | 34 | } |
28 | private handleError(error: any): Promise<any> { | 35 | private handleError(error: any): Promise<any> { |
29 | console.error('An error occured', error); | 36 | console.error('An error occured', error); |