|
[index.cshtml]
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.data).Load("GridLoad").Columns(col=> {
col.Field("OrderID").IsPrimaryKey(true).HeaderText("Order ID").Width("120").Add();
col.Field("EmployeeID").HeaderText("Employee ID").Width("170").Add();
col.Field("CustomerID").HeaderText("Customer Name").Edit(new { create = "create", read = "read", destroy = "destroy", write = "write" }).Width("170").Add();
col.Field("ShipCity").HeaderText("Ship City").Edit(new { create = "create1", read = "read1", destroy = "destroy1", write = "write1" }).Width("170").Add();
}).AllowPaging().EditSettings(edit => edit.AllowAdding(true).AllowDeleting(true).AllowEditing(true)).Render()
<script type="text/javascript">
function GridLoad() {
this.getColumnByField("CustomerID").validationRules = {
required: [customFn.bind(), "Please enter validate customer"] // define validation rule in customerID column
}
}
function customFn(args) {
if (args.value != "HANAR") {
return true;
} else {
return false;
}
}
var dropDownListObj;
var dropDownListObj1;
function create(args) {
elemCustomerID = document.createElement('input');
return elemCustomerID;
}
function write(args) {
dropDownListObj = new ej.dropdowns.DropDownList({
dataSource: document.getElementById('Grid')['ej2_instances'][0].dataSource,
fields: { text: 'CustomerID', value: 'CustomerID' },
placeholder: 'Select an CustomerID',
allowFiltering:true,
change: function (args) {
console.log('called');
dropDownListObj1.enabled = true;
var tempQuery = new ej.data.Query().where('CustomerID', 'equal', dropDownListObj.value);
dropDownListObj1.query = tempQuery;
dropDownListObj1.text = null;
dropDownListObj1.dataBind();
},
popupHeight: '270px',
value: args.rowData.CustomerID
});
dropDownListObj.appendTo(elemCustomerID);
}
function destroy() {
dropDownListObj.destroy();
}
function read(args) {
return dropDownListObj.value
}
function create1(args) {
elemEmployeeID = document.createElement('input');
return elemEmployeeID;
}
function write1(args) {
dropDownListObj1 = new ej.dropdowns.DropDownList({
dataSource: document.getElementById('Grid')['ej2_instances'][0].dataSource,
fields: { text: 'ShipCity', value: 'ShipCity' },
placeholder: 'Select an ShipCity',
change: function (args) {
console.log('called')
},
popupHeight: '270px',
enabled:false,
value: args.rowData.ShipCity
});
dropDownListObj1.appendTo(elemEmployeeID);
}
function destroy1() {
dropDownListObj1.destroy();
}
function read1(args) {
return dropDownListObj1.value
} |