[index.cshtml]
<ejs-grid id="Grid" dataSource="ViewBag.dataSource" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })" allowPaging="true">
<e-grid-pagesettings pageSize="5"></e-grid-pagesettings>
<e-datamanager url="/Home/UrlDatasource" insertUrl="/Home/Insert" updateUrl="/Home/Update" adaptor="UrlAdaptor"></e-datamanager>
<e-grid-editSettings allowAdding="true" allowEditing="true"></e-grid-editSettings>
<e-grid-columns>
. . . .
<e-grid-column field="EmployeeID" headerText="Employee ID" width="110"></e-grid-column>
<e-grid-column field="ShipCountry" valueAccessor="@("shipCountry")" headerText="ShipCountry" edit="@(new {create = "create", read = "read", destroy = "destroy", write = "write"})" width="110"></e-grid-column>
<e-grid-column field="ShipCity" valueAccessor="@("shipCity")" width="110" edit="@(new {create = "createcity", read = "readcity", destroy = "destroycity", write = "writecity"})"> </e-grid-column>
</e-grid-columns>
</ejs-grid>
<script>
function shipCountry(field, data, column) {
var country;
. . . .
data[field] = country;
return country;
}
function shipCity(field, data) {
var city;
. . . .
data[field] = city;
return city;
}
//Remote data
window["shippedData"] = new ej.data.DataManager({
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/Orders/',
adaptor: new ej.data.ODataV4Adaptor,
});
function write(args) {
countryObj = new ej.dropdowns.DropDownList({
dataSource: shippedData, // bind the Remote data
fields: { value: 'EmployeeID', text: 'ShipCountry' },
value: args.rowData['ShipCountry'],
change: function () {
// pass the query from “ShipCountry” to “ShipCity” using foreignKeyValue(“EmployeeID”)
stateObj.enabled = true;
var tempQuery = new ej.data.Query().where('EmployeeID', 'equal', countryObj.value);
stateObj.query = tempQuery;
stateObj.text = null;
stateObj.dataBind();
},
placeholder: 'Select a country',
floatLabelType: 'Never'
});
countryObj.appendTo(countryElem);
};
</script> |