<ejs-button id="deletebtn" cssClass="e-flat" isPrimary="true" iconCss="e-btn-sb-icons e-play-icon" content="Delete Row"></ejs-button>
<ejs-grid id="Grid" dataSource="ViewBag.datasource" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })" allowPaging="true">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" newRowPosition="Top" mode="Batch"></e-grid-editSettings>
<e-grid-selectionsettings type="Multiple" mode="Row"></e-grid-selectionsettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" validationRules="@(new { required=true, number=true})" width="140"></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" validationRules="@(new { required=true})" textAlign="Right" editType="numericedit" format="C2" width="140"></e-grid-column>
<e-grid-column field="OrderDate" headerText="Order Date" editType="datepickeredit" customFormat="@(new {type = "date", format = "M/d/y" })"></e-grid-column>
<e-grid-column field="ShipCity" headerText="Ship City" editType="dropdownedit" width="140"></e-grid-column>
</e-grid-columns>
</ejs-grid>
<script>
document.getElementById("deletebtn").addEventListener('click', function () {
var grid = document.getElementById("Grid").ej2_instances[0]; // Grid Instances
var selectedRow = grid.getSelectedRows();
if (selectedRow.length > 0) { // check row is selected or not
for (var i = 0; i < selectedRow.length; i++) {
grid.deleteRow(selectedRow[i]);
}
}
</script> |