Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
148913 | Nov 7,2019 04:56 PM UTC | Nov 18,2019 03:42 AM UTC | Angular - EJ 2 | 8 |
![]() |
Tags: TreeGrid |
<ejs-treegrid [dataSource]='data' childMapping='subtasks' [treeColumnIndex]='1' [pageSettings]='pageSetting' allowPaging='true'> ------ </ejs-treegrid> in ts export class DefaultPagingComponent implements OnInit { public data: Object[] = []; public pageSetting: Object; ngOnInit(): void { ------- this.pageSetting = { pageCount: 2, pageSizes: true } ; } } |
import { Component, ViewChild, ViewEncapsulation, OnInit, Inject } from '@angular/core';
import { DataManager, WebApiAdaptor, Query, DataUtil } from '@syncfusion/ej2-data';
import { TreeGridComponent } from '@syncfusion/ej2-angular-treegrid';
let primaryKey: any;
let selectedRecord: any;
@Component({
selector: 'fetchdata',
templateUrl: './fetchdata.component.html',
encapsulation: ViewEncapsulation.Emulated
})
export class FetchDataComponent {
public data: any;
public toolbarOptions: string[] | undefined;
public editSettings: Object | undefined;
@ViewChild('treegrid')
public treegrid: TreeGridComponent;
ngOnInit(): void {
this.editSettings = { allowEditing: true, allowAdding: true, allowDeleting: true, mode: "Row", newRowPosition:"Below" };
this.toolbarOptions = ['Add', 'Delete', 'Update', 'Cancel'];
this.data = new DataManager({
url: 'api/SelfReferenceData',
adaptor: new CustomAdaptor()
});
}
actionBegin(args: any): void {
if (args.requestType == "save" && args.action == "add") {
primaryKey = selectedRecord.TaskID;
}
}
rowSelected(args: any): void {
selectedRecord = args.data;
}
}
////// Extending the WebApiAdaptor and overriding the insert method.
class CustomAdaptor extends WebApiAdaptor {
public insert(dm: DataManager, data: Object, tableName?: string): Object {
dm.dataSource.url = dm.dataSource.url + "?$key=" + primaryKey //// sending the primary key of selected record in query string
return {
type: 'POST',
url: dm.dataSource.url,
data: JSON.stringify(data),
};
}
}
[Controller.cs] [HttpPost]
public object Post([FromBody]SelfReferenceData value)
{
var queryString = Request.Query;
StringValues keys;
queryString.TryGetValue("$key", out keys); /// retrieving the key value from querystring
int key = Int32.Parse(keys[0]);
SelfReferenceData.tree.Insert(0, value);
var data = SelfReferenceData.tree.ToList();
return Json(new { result = data, count = data.Count });
} |
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.