Index.js
export class ContextMenuSample extends SampleBase {
constructor() {
super(...arguments);
this.groupOptions = { showGroupedColumn: true };
this.contextMenuItems = [
"FirstPage",
"PrevPage",
"LastPage",
"NextPage",
{ text: "SortColumn", target: ".e-gridheader", id: "sortColumn" },
{ text: "ClearSorting", target: ".e-gridheader", id: "clearSort" }
];
this.editing = { allowDeleting: true, allowEditing: true };
}
contextMenuClick(args) {
if (this.grid && args.item.id === "sortColumn") {
this.grid.contextMenuModule.isOpen = false; // set the isOpen as false to perform sorting operation.
if (!this.grid.sortSettings.columns.length) {
this.grid.sortColumn(args.column.field, "Descending", false);
} else {
this.grid.sortColumn(args.column.field, "Descending", true);
}
}
if (this.grid && args.item.id === "clearSort") {
this.grid.clearSorting();
}
}
render() {
return (
<div className="control-pane">
<div className="control-section">
<GridComponent
ref={g => (this.grid = g)}
dataSource={orderDetails}
allowPaging={true}
allowSorting={true}
allowExcelExport={true}
allowPdfExport={true}
contextMenuItems={this.contextMenuItems}
editSettings={this.editing}
contextMenuClick={this.contextMenuClick.bind(this)}
>
<ColumnsDirective>
<ColumnDirective
field="OrderID"
headerText="Order ID"
width="120"
textAlign="Right"
isPrimaryKey={true}
/>
<ColumnDirective
field="CustomerName"
headerText="Customer Name"
/>
<ColumnDirective
field="Freight"
headerText="Freight"
format="C2"
textAlign="Right"
editType="numericedit"
/>
<ColumnDirective
field="ShipName"
headerText="Ship Name"
width="200"
/>
<ColumnDirective
field="ShipCountry"
headerText="Ship Country"
width="150"
editType="dropdownedit"
/>
<ColumnDirective
field="ShipCity"
headerText="Ship City"
width="150"
/>
</ColumnsDirective>
<Inject
services={[
Resize,
Sort,
ContextMenu,
Filter,
Page,
ExcelExport,
Edit,
PdfExport
]}
/>
</GridComponent>
</div>
</div>
);
}
}
render(<ContextMenuSample />, document.getElementById("sample")); |