Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
150245 | Dec 27,2019 11:23 PM UTC | Feb 3,2020 11:13 AM UTC | Angular - EJ 2 | 5 |
![]() |
Tags: Grid |
actionBegin(args: SaveEventArgs): void {
if (args.requestType === 'beginEdit' || args.requestType === 'add') {
this.submitClicked = false;
this.orderForm = this.createFormGroup(args.rowData);
}
if (args.requestType === 'save') {
this.submitClicked = true;
if (this.orderForm.valid) {
args.data = this.orderForm.value;
} else {
args.cancel = true;
}
}
}
|
createFormGroup(data: IOrderModel): FormGroup {
return new FormGroup({
id: new FormControl(data.id, Validators.required),
name: new FormControl(data.name, Validators.required)
});
}
|
public dataSourceChanged(state: DataSourceChangedEventArgs): void {
if (state.action === 'add') {
this.crudService.addRecord(state).subscribe(() => {this.grid.notify('recordAdded', state); state.endEdit()});
} else if (state.action === 'edit') {
this.crudService.updateRecord(state).subscribe(() => state.endEdit());
} else if (state.requestType === 'delete') {
this.crudService.deleteRecord(state).subscribe(() => {
state.endEdit();
});
}
} |
crudService.ts
/** POST: add a new record to the server using the observable concept */
addRecord(state: DataSourceChangedEventArgs): Observable<Customer> {
return this.http.post<Customer>(this.customersUrl, state.data, httpOptions);
} |
public dataStateChange(state: DataStateChangeEventArgs): void {
this.crudService.execute(state);
} |
crudService.ts
public execute(state: any): void {
this.getAllData().subscribe(x => super.next(x as DataStateChangeEventArgs));
} |
crudService.ts
/** GET all data from the server */
getAllData(): Observable<any[]> {
debugger;
return this.http.get<Customer[]>(this.customersUrl)
.map((response: any) => (<any>{
result: response,
count: response.length
}))
.map((data: any) => data);
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.