diff --git a/src/app/pages/statements/components/busStop2/busStop2.component.ts b/src/app/pages/statements/components/busStop2/busStop2.component.ts index 819d6b6..c09c21e 100644 --- a/src/app/pages/statements/components/busStop2/busStop2.component.ts +++ b/src/app/pages/statements/components/busStop2/busStop2.component.ts @@ -25,7 +25,7 @@ export class BusStop2 { // source: LocalDataSource = new LocalDataSource(); public showGrid: boolean; - public rowData: any[]; + public rowData: any[] = []; public rowCount: string; public regions: RegionSelectList[]; public states: StateCommonSelectList[]; @@ -40,26 +40,43 @@ export class BusStop2 { protected service: BusStop2Service, private dataService: BusStopCreateService, ) { + this.gridOptions = {}; + this.gridOptions.rowModelType = 'virtual'; + this.showGrid = true; + let dataSource = { + rowCount: null, // behave as infinite scroll + getRows: function (params) { + // At this point in your code, you would call the server, using $http if in AngularJS. + // To make the demo look real, wait for 500ms before returning + // take a slice of the total rows + let rowsThisPage = this.rowData.slice(params.startRow, params.endRow); + // if on or after the last page, work out the last row. + let lastRow = -1; + if (this.rowData.length <= params.endRow) { + lastRow = this.rowData.length; + } + // call the success callback + params.successCallback(rowsThisPage, lastRow); + }.bind(this) + }; + this.gridOptions.datasource = dataSource; this.dataService.getModels().then(models => { this.regions = models.regionSelectListDsM as RegionSelectList[]; this.states = models.stateCommonSelectListDsM as StateCommonSelectList[]; this.surfaceTypes = models.surfaceTypeSelectListDsM as SurfaceTypeSelectList[]; this.settlements = models.settlementSelectListDsM as SettlementSelectList[]; this.roads = models.roadSelectListDsM as RoadSelectList[]; + this.service.getData().then((data) => { + if (data.length){ + // this.source.load(data); + this.rowData = data; + } else { + this.rowData = [new busStop2]; + } this.createColumnDefs(); + this.gridOptions.api.refreshVirtualPageCache(); + }); }); - this.gridOptions = {}; - // this.gridOptions.rowModelType = 'virtual'; - this.service.getData().then((data) => { - console.log(data); - if (data.length){ - // this.source.load(data); - this.rowData = data; - } else { - this.rowData = [new busStop2]; - } - }); - this.showGrid = true; } onDeleteConfirm(event): void { @@ -69,7 +86,31 @@ export class BusStop2 { event.confirm.reject(); } } - + public addNewRow() { + this.rowData.unshift(new busStop2()); + this.gridOptions.api.refreshVirtualPageCache(); + } + private setRowData(data) { + let dataSource = { + rowCount: null, // behave as infinite scroll + getRows: function (params) { + // At this point in your code, you would call the server, using $http if in AngularJS. + // To make the demo look real, wait for 500ms before returning + setTimeout( function() { + // take a slice of the total rows + var rowsThisPage = data.slice(params.startRow, params.endRow); + // if on or after the last page, work out the last row. + var lastRow = -1; + if (data.length <= params.endRow) { + lastRow = data.length; + } + // call the success callback + params.successCallback(rowsThisPage, lastRow); + }, 500); + } + }; + this.gridOptions.datasource = dataSource; + } private createColumnDefs() { this.columnDefs = [ { diff --git a/src/app/pages/statements/components/busStop2/busStop2.service.ts b/src/app/pages/statements/components/busStop2/busStop2.service.ts index 9b1889d..b04ebf4 100644 --- a/src/app/pages/statements/components/busStop2/busStop2.service.ts +++ b/src/app/pages/statements/components/busStop2/busStop2.service.ts @@ -11,19 +11,26 @@ export class BusStop2Service { private headers = new Headers({'Content-Type': 'application/json'}); constructor(private http: Http) { } getData(): Promise { - // let busStops: BusStop2[] = [{ - // id: 1, - // road: 'Test', - // region: 'Test', - // locationLeft: '1', - // locationRight: '1', - // state: 'Test' - // }]; - // return Promise.resolve(busStops); - return this.http.get(this.url) - .toPromise() - .then(response => response.json().busStopEditDsM as busStop2[]) - .catch(this.handleError); + let busStops: busStop2[] = [{ + roadId: 1, + regionId: 1, + settlementId: 1, + surfaceTypeId: '1', + locationLeft: '1', + locationRight: '1', + stateCommonId: 1, + areaStopAvailability: '', + areaLandAvailability: '', + pocketAvailability: '', + toiletAvailability: '', + yearBuild: '', + yearRepair: '', + }]; + return Promise.resolve(busStops); + // return this.http.get(this.url) + // .toPromise() + // .then(response => response.json().busStopEditDsM as busStop2[]) + // .catch(this.handleError); } private handleError(error: any): Promise { console.error('An error occured', error); -- libgit2 0.21.4