[Index.cshtml]
<div>
<ejs-grid id="Grid" load="onLoad" allowExcelExport="true" toolbarClick="onToolBarClick">
<e-data-manager url="@Url.Action("UrlDatasource","Home",new { userRole = @ViewBag.userRole})" insertUrl="@Url.Action("Insert","Home")" updateUrl="@Url.Action("Update","Home")" removeUrl="@Url.Action("Remove","Home")" adaptor="UrlAdaptor" ></e-data-manager>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" validationRules="@(new { required=true})" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer Name" validationRules="@(new { required=true})" width="150"></e-grid-column>
<e-grid-column field="Freight" headerText="Freight" format="C2" width="120"></e-grid-column>
<e-grid-column field="ShipCity" headerText="Ship City" minWidth="20" maxWidth="500"></e-grid-column>
<e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
<script>
function onLoad(args) {
var gridObj = document.getElementById('Grid').ej2_instances[0];
var userRole = "@ViewBag.userRole";
if (userRole === "admin") {
this.editSettings = { allowAdding: true, allowEditing: true, allowDeleting: true, mode: "Dialog", showDeleteConfirmDialog: true };
this.toolbar = ["Add", "Edit", "Update", "Delete","Cancel", "ExcelExport"];
}
} |