|
@{
List<object> ContextMenuitems = new List<object>();
ContextMenuitems.Add(new { text = "Copy with headers", target = ".e-content", id = "copywithheader" });
}
<div>
<ejs-grid id="Grid" dataSource="ViewBag.DataSource" contextMenuItems="ContextMenuitems" contextMenuOpen="contextOpen" contextMenuClick="contextMenuClick" allowGrouping="true" allowFiltering="true" allowPaging="true">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Normal"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer Name" width="150"></e-grid-column>
<e-grid-column field="Freight" headerText="Freight" format="C2" width="120"></e-grid-column>
<e-grid-column field="OrderDate" headerText="Order Date" type='date' format='yMd' editType="datepickeredit" width="170"></e-grid-column>
<e-grid-column field="Verified" headerText="Verified" width="150"></e-grid-column>
<e-grid-column field="ShipCountry" headerText="Ship Country" width="140"></e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
<script>
function contextMenuClick(args) {
if (args.item.id === 'copywithheader') {
this.copy(true);
}
}
function contextOpen(args) {
if (args.rowInfo.rowData.OrderID % 2 == 0) {
args.element.ej2_instances[0].enableItems(['Copy with headers'], false); //disable
}
else {
args.element.ej2_instances[0].enableItems(['Copy with headers'], true); //enable
}
}
</script>
|