Index.cshtml
<div class="control-section">
@Html.EJS().Grid("DefaultPaging").DataSource((IEnumerable<object> )ViewBag.datasource).DataBound("dataBound").ActionComplete("actionComplete").ActionBegin("actionBegin").Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").Width("120").IsPrimaryKey(true).Filter(new { type = "CheckBox" }).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("CustomerID").HeaderText("Customer Name").Width("170").Add();
col.Field("OrderDate").HeaderText("Order Date").Width("130").EditType("datepickeredit").Format("yMd").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("Freight").HeaderText("Freight").Width("120").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("ShipCity").EditType("dropdownedit").HeaderText("Ship city").Width("150").Add();
col.Field("ShipAddress").EditType("dropdownedit").HeaderText("ShipAddress").Width("150").Add();
col.Field("EmployeeID").HeaderText("EmployeeID").Width("150").Add();
}).Height("400").AllowPaging().Toolbar(new List<string>
() { "Add", "Edit", "Delete", "Update", "Cancel" }).AllowFiltering().FilterSettings(filter => filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu)).EditSettings(edit => { edit.AllowEditing(true).AllowAdding(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Dialog); }).Render()
</div>
<script>
var cancelFlag = true;
var flag = true;
function dataBound() {
if (ej.base.Browser.isDevice && flag) { //will get executed in mobile view alone.
this.getColumnByField("ShipAddress").visible = false;
this.getColumnByField("EmployeeID").visible = false;
flag = false;
this.refreshColumns();
}
}
function actionBegin(args) {
if (ej.base.Browser.isDevice) { // hide the columns only in mobile view alone.
if (args.requestType === "beginEdit" || args.requestType === "add") {
this.showColumns(["ShipAddress", "EmployeeID"]);
}
if (args.requestType === "save") {
this.hideColumns(["ShipAddress", "EmployeeID"]);
}
if (args.requestType === "cancel" && cancelFlag) {
cancelFlag = false;
this.hideColumns(["ShipAddress", "EmployeeID"]);
}
}
}
function actionComplete(args) {
if (ej.base.Browser.isDevice) {
if (args.requestType === "cancel" && !cancelFlag) {
cancelFlag = true;
this.hideColumns(["ShipAddress", "EmployeeID"]);
}
}
}
</script>
|