Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
148873 | Nov 6,2019 07:06 PM UTC | Nov 12,2019 04:00 AM UTC | jQuery | 3 |
![]() |
Tags: ejGrid |
$(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> |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.