@(Html.EJ().Grid<object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.ClientSideEvents(ce=> { ce.CellSave("cellSave"); })
.AllowPaging() /*Paging Enabled*/
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Batch); })
.ToolbarSettings(toolbar =>
{
-------------
})
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Add();
col.Field("Freight").HeaderText("Freight").AllowEditing(false).TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add();
}))
</div>
<script type="text/javascript">
function cellSave(args) {
var gridObj = $("#FlatGrid").data("ejGrid");
var rowIndex = gridObj.selectedRowsIndexes;
if (args.columnName == "EmployeeID") { // after the change the employeeid column value
var employeeID = args.value;// getting the new value in employeeid column
var cellIndex = 2; // Freight column's cellIndex
gridObj.setCellText(rowIndex, cellIndex, employeeID * 5);
}
}
</script>
|
Used to update a particular cell value.
NOTE
It will work only for Local Data.This method applicable for all editMode’s except batch edit mode.
@(Html.EJ().Grid<object>("FlatGrid")
.ClientSideEvents(ce=> { ce.CellSave("cellSave"); })
-------------------
<script type="text/javascript">
function cellSave(args) {
var gridObj = $("#FlatGrid").data("ejGrid");
var rowIndex = gridObj.selectedRowsIndexes;
if (args.columnName == "EmployeeID") {
debugger
var employeeID = args.value;// getting the new value
var cellIndex = 4; // Freight column's cellIndex
gridObj.model.columns[4]['allowEditing'] = true; // 4 denotes the freight column’s index, enable the allowEditing for the disabled column
gridObj.setCellValue(rowIndex, "Freight", employeeID * 5);
gridObj.model.columns[4]['allowEditing'] = false; // 4 denotes the freight column’s index, enable the allowEditing for the disabled column
}
}
</script>
|
Hi Bruno,
We have analyzed your query and we found that you are using inline editMode in grid. Since CellSave event will works only in batch edit mode so we suggest you to use EndEdit event for Inline edit mode.
Please refer the code sample:
@(Html.EJ().Grid<object>("FlatGrid")
.ClientSideEvents(eve=>eve.EndEdit("endEdit")) -------------------
<script type="text/javascript"> function endEdit(args) { var gridObj = $("#FlatGrid").data("ejGrid"); var rowIndex = gridObj.selectedRowsIndexes; var employeeID = args.data.EmployeeID;// getting the new value var cellIndex = 4; // Freight column's cellIndex gridObj.setCellText(rowIndex, cellIndex, employeeID * 5);
}
</script> |
Please find the documentation link
https://help.syncfusion.com/api/js/ejgrid#events:endedit
Please let us know if you need any further assistance.
Regards,
Balasubramanian Masilamani
@(Html.EJ().Grid<object>("FlatGrid")
.AllowPaging()
.ClientSideEvents(cevent => cevent.ActionComplete("complete"))
---
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width(75).Add();
col.Field("Freight").HeaderText("Freight").Width(100).Add();
col.Field("EmployeeID").HeaderText("Employee ID").Width(90).Add();
col.HeaderText("Calculated Column").Template("<span id='CalcCol'>{{:EmployeeID * Freight }}</span>").Width(90).Add();
}))
</div>
<script type="text/javascript">
function complete(args) {
if (args.requestType == "beginedit" || args.requestType == "add") {
$("#" + this._id + "EmployeeID").keyup(function (event) {
Valuechange();
});
$("#" + this._id + "Freight").keyup(function (event) {
Valuechange();
});
}
}
function Valuechange(args) {
var employeeID = $("#FlatGrid" + "EmployeeID").val();
var freight = $("#FlatGrid" + "Freight").val();
$("#CalcCol")[0].innerHTML = parseFloat(employeeID) * parseFloat(freight);
}
</script>
|