|
export class FetchEmployee extends React.Component<RouteComponentProps<{}>, FetchEmployeeDataState> {
public toolbarOptions: any = ['Add', 'Delete', 'Update', 'Cancel'];
public editSettings: any = { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' };
constructor(props) {
super(props);
}
public onload(args: any) {
let dm: any = new DataManager({
url: "/Home/UrlDatasource",
adaptor: new UrlAdaptor(),
insertUrl: "/Home/Insert",
updateUrl: "/Home/Update",
removeUrl:"/Home/Remove"
});
(this as any).grid.dataSource = dm;
}
public dataManger: Object = new DataManager({
url: 'https://js.syncfusion.com/demos/ejServices/Wcf/Northwind.svc/Orders',
adaptor: new ODataAdaptor,
crossDomain: true
});
public dataManger2: Object = new DataManager({
url: 'https://js.syncfusion.com/demos/ejServices/Wcf/Northwind.svc/Customers',
adaptor: new ODataAdaptor,
crossDomain: true
});
public secondChildGrid: any = {
// binding remote data
dataSource: this.dataManger2,
queryString: 'CustomerID',
allowPaging: true,
pageSettings: { pageSize: 6, pageCount: 5 },
columns: [
{ field: 'CustomerID', headerText: 'Customer ID', textAlign: 'Right', width: 75 },
{ field: 'ContactName', headerText: 'Contact Name', width: 100 },
{ field: 'Address', headerText: 'Address', width: 120 },
{ field: 'Country', headerText: 'Country', width: 100 }
]
};
public childGrid: any = {
//binding remote data
dataSource: this.dataManger,
queryString: 'EmployeeID',
allowPaging: true,
pageSettings: { pageSize: 6, pageCount: 5 },
columns: [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120 },
{ field: 'ShipCity', headerText: 'Ship City', width: 120 },
{ field: 'Freight', headerText: 'Freight', width: 120 },
{ field: 'ShipName', headerText: 'Ship Name', width: 150 }
],
childGrid: this.secondChildGrid
};
public render() {
return (<div className='control-section'>
<GridComponent ref={g => (this as any).grid = g} load={this.onload.bind(this)} editSettings={this.editSettings} toolbar={this.toolbarOptions} childGrid={this.childGrid} allowSorting={true} >
<ColumnsDirective>
<ColumnDirective field='EmployeeID' headerText='Employee ID' width='125' textAlign='Right' />
<ColumnDirective field='ShipCity' headerText='ShipCity' width='125' />
</ColumnsDirective>
<Inject services={[DetailRow, Page, Sort, Edit, Toolbar]} />
</GridComponent>
</div>)
}
}
|
|
[index.js]
export class Hierarchy extends SampleBase {
constructor() {
super(...arguments);
this.menuItems = [
{
text: 'Cut',
iconCss: 'e-cm-icons e-cut'
},
{
text: 'Copy',
iconCss: 'e-cm-icons e-cm-copy'
}];
this.childGrid = {
dataSource: orderDatas,
queryString: 'EmployeeID',
allowPaging: true,
pageSettings: { pageSize: 6, pageCount: 5 },
columns: [
. . .
{
headerText: 'Context Menu', template:this.gridTemplate, width: 150
}
],
};
}
gridTemplate(props) {
function btnClick (e) {
var contextMenu = document.getElementById('contextMenu').ej2_instances[0];
var x = e.currentTarget.getBoundingClientRect().top;
var y = e.currentTarget.getBoundingClientRect().left;
contextMenu.close();
// open the context menu with the given coordinates.
contextMenu.open(x,y+60);
}
return (<div>
// render the button
<ButtonComponent onClick={btnClick.bind(this) }>Context Menu</ButtonComponent>
</div>);
}
render() {
return (<div className='control-pane'>
<div className='control-section'>
// render the context menu
<ContextMenuComponent id="contextMenu" items={this.menuItems} />
<GridComponent dataSource={employeeData} childGrid={this.childGrid} allowSorting={true}>
<ColumnsDirective>
. . .
<Inject services={[DetailRow, Page,ContextMenu, Sort]}/>
</GridComponent>
</div>
</div>);
}
}
render(<Hierarchy />, document.getElementById('sample'));
|