This repository was archived by the owner on Jul 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontext-menu.tsx
More file actions
96 lines (90 loc) · 5.51 KB
/
context-menu.tsx
File metadata and controls
96 lines (90 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import { GridComponent, ColumnsDirective, ColumnDirective, Resize, Sort, ContextMenu, Filter, Page, ExcelExport, PdfExport, Edit, Inject } from '@syncfusion/ej2-react-grids';
import { GroupSettingsModel, FilterSettingsModel, ContextMenuItem, EditSettingsModel } from '@syncfusion/ej2-react-grids';
import { orderDetails } from './data';
import { SampleBase } from '../common/sample-base';
import './grid-context-menu.css';
export class ContextMenuSample extends SampleBase<{}, {}> {
public groupOptions: GroupSettingsModel = { showGroupedColumn: true };
public contextMenuItems: ContextMenuItem[] = ['AutoFit', 'AutoFitAll',
'SortAscending', 'SortDescending', 'Copy', 'Edit', 'Delete', 'Save',
'Cancel', 'PdfExport', 'ExcelExport', 'CsvExport', 'FirstPage', 'PrevPage',
'LastPage', 'NextPage'];
public editing: EditSettingsModel = { allowDeleting: true, allowEditing: true }
render() {
return (
<div className='control-pane'>
<div className='control-section'>
<GridComponent id='gridcomp' dataSource={orderDetails} allowPaging={true} allowSorting={true}
allowExcelExport={true} allowPdfExport={true} contextMenuItems={this.contextMenuItems}
editSettings={this.editing}>
<ColumnsDirective>
<ColumnDirective field='OrderID' headerText='Order ID' width='120' textAlign='Right' isPrimaryKey={true}></ColumnDirective>
<ColumnDirective field='CustomerName' headerText='Customer Name'></ColumnDirective>
<ColumnDirective field='Freight' headerText='Freight' format='C2' textAlign='Right' editType='numericedit' />
<ColumnDirective field='ShipName' headerText='Ship Name' width='200'></ColumnDirective>
<ColumnDirective field='ShipCountry' headerText='Ship Country' width='150' editType='dropdownedit'></ColumnDirective>
<ColumnDirective field='ShipCity' headerText='Ship City' width='150'></ColumnDirective>
</ColumnsDirective>
<Inject services={[Resize, Sort, ContextMenu, Filter, Page, ExcelExport, Edit, PdfExport]} />
</GridComponent>
</div>
<div id="action-description">
<p>
This sample demonstrates the usage of context menu in Grid component. Right click anywhere on the Grid to view context
menu.
</p>
</div>
<div id="description">
<p>
Grid has options to show the context menu when right click on it. To configure the items in context menu, you should define
either default or custom item in
<code><a target="_blank" className="code"
href="http://ej2.syncfusion.com/react/documentation/grid/api-gridComponent.html#contextmenuitems-contextmenuitem---contextmenuitemmodel">contextMenuItems
</a></code>. Each item will be shown based on it target. The default items are
</p>
<ul>
<li>
<code>edit</code> - Edit the current record.</li>
<li>
<code>delete</code> - Delete the current record.</li>
<li>
<code>save</code> - Save the edited record.</li>
<li>
<code>cancel</code> - Cancel the edited state.</li>
<li>
<code>copy</code> - Copy the selected records.</li>
<li>
<code>pdfExport</code> - Export the grid as Pdf format.</li>
<li>
<code>excelExport</code> - Export the grid as Excel format.</li>
<li>
<code>csvExport</code> - Export the grid as CSV format.</li>
<li>
<code>sortAscending</code> - Sort the current column in ascending order.</li>
<li>
<code>sortDescending</code> - Sort the current column in descending order.</li>
<li>
<code>firstPage</code> - Go to the first page.</li>
<li>
<code>prevPage</code> - Go to the previous page.</li>
<li>
<code>lastPage</code> - Go to the last page.</li>
<li>
<code>nextPage</code> - Go to the next page.</li>
</ul>
<br />
<p>
In this demo, Context Menu feature has enabled by defining the
<code> contextMenuItems </code> property with all default items.
</p>
<p style={{ fontWeight: 500 }}>Injecting Module:</p>
<p>
Grid component features are segregated into individual feature-wise modules. To use context menu feature, we need to inject <code>ContextMenu</code> modeule into the <code>services</code>
</p>
</div>
</div >
)
}
}