|
<ejs-grid id="Grid" allowPaging="true" rowselected="rowselected" toolbar="@( new List<object>() {"Add","Edit","Delete","Update","Cancel"})">
…
</ejs-grid>
<script>
function rowselected(e) {
this.editModule.startEdit(e.row);
}
</script> |
|
<div id="ControlRegion">
<button onclick="update()">Save</button>
<button onclick="cancel()">Cancel</button>
<ejs-grid id="Grid" queryCellInfo="queryCellInfo" dataSource=@ViewBag.datasource allowPaging="true">
<e-grid-selectionsettings checkboxOnly="true" persistSelection="true"></e-grid-selectionsettings>
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditOnDblClick="false" allowEditing="true" mode="Batch"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column type="checkbox" width="50"></e-grid-column>
<e-grid-column field="OrderID" isPrimaryKey="true" headerText="OrderID" width="120"></e-grid-column>
<e-grid-column field="EmployeeID" isPrimaryKey="true" headerText="EmployeeID" template="#template_col1" width="120"></e-grid-column>
<e-grid-column field="CustomerID" headerText="CustomerID" template="#template_col2" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
<script id="template_col1" type="text/x-template">
<input class='txtbo employeeid' />
</script>
<script id="template_col2" type="text/x-template">
<input class='e-input customerid' value="${CustomerID}"/>
</script>
<script>
function queryCellInfo(args) {
if (args.cell.classList.contains('e-templatecell')) {
if (args.column.field === 'EmployeeID') {
var targEle1 = args.cell.querySelector('.txtbo.employeeid');
// rendering Essential JavaScript 2 NumericTextBox component in template
var ntextBox = new ej.inputs.NumericTextBox({
value: args.data.EmployeeID, decimals : 0,
format :"N"
});
ntextBox.appendTo(targEle1);
}
}
}
function update() {
var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0];
var rows = grid.getSelectedRows();
rows.forEach((row) => {
// getting the modified data in the selected rows
var EmpID = parseInt(row.getElementsByClassName('employeeid')[0].value);
var CustID = row.getElementsByClassName('customerid')[0].value;
var index = parseInt(row.getAttribute('aria-rowindex'));
var data = grid.currentViewData[index];
changed.push(Object.assign(data, {EmployeeID:EmpID,CustomerID:CustID}));
})
changes.changedRecords = changed;
grid.renderModule.sendBulkRequest({ changes, name: "bulk-save" });
changed = [];
}
function cancel() {
var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0];
grid.refresh();
}
</script>
|