$(function () {
window.foreignkeydata = {};
var dataManager = ej.DataManager({
url: "/api/Default",
adaptor: new ej.WebApiAdaptor(),
offline: true
});
dataManager.ready.done(function (e) {
window.foreignkeydata = e.result; // store the foreignkey dataSource in window variable.
})
$("#Grid").ejGrid({
…………
templateRefresh: function (args) {
if (args.column.headerText == "Type2") {
var value = window.foreignkeydata.filter(e => e.EmployeeID == args.data.EmployeeID); // filter the foreignkey datasource using foreignkey field.
args.cell.innerText = value[0].FirstName;
}
},
columns: [
………………………………………….
{ field: "EmployeeID", headerText: 'Type1', foreignKeyField: "EmployeeID", foreignKeyValue: "FirstName", dataSource: dataManager, validationRules: { required: true } },
{ headerText: "Type2", template: "<span></span > " },
],
});
});
|
$(function () {
window.foreignkeydata = {};
var ForiegnkeyData = ej.DataManager({
url: "/api/Default",
adaptor: new ej.WebApiAdaptor(),
offline: true
});
var GridData = ej.DataManager({
url: "/api/Grid",
adaptor: new ej.WebApiAdaptor(),
offline: true
});
ForiegnkeyData.ready.done(function (e) {
window.foreignkeydata = e.result;
})
GridData.ready.done(function (e) {
$("#Grid").ejGrid({
dataSource: ej.DataManager({
json: e.result,
adaptor: new ej.remoteSaveAdaptor()
}),
…………….
templateRefresh: function (args) {
if (args.column.headerText == "Type2") {
var value = window.foreignkeydata.filter(e => e.EmployeeID == args.data.EmployeeID);
args.cell.innerText = value[0].FirstName;
}
},
columns: [
……………………………………
{ field: "EmployeeID", headerText: 'Type1', foreignKeyField: "EmployeeID", foreignKeyValue: "FirstName", dataSource: ForiegnkeyData, validationRules: { required: true } },
{ headerText: "Type2", template: "<span></span > " },
],
………………………
});
});
});
</script> |