<script type="text/javascript">
$(function () {
………………………………………………………
$("#Grid").ejGrid({
……………………………………………………………………….
columns: [
{ field: "OrderID", isPrimaryKey: true, headerText: "Order ID", textAlign: ej.TextAlign.Right, validationRules: { required: true, number: true }, width: 90 },
…………………………………………………………………………..
{
field: "EmployeeID", headerText: 'Employee ID', foreignKeyField: "EmployeeID", foreignKeyValue: "num", dataSource: window.employeeView, validationRules: { required: true },
editTemplate: {
create: function () {
return "<input>";
},
read: function (args) {
var val = args.ejNumericTextbox("model.value");
var obj = args.closest('.e-grid').ejGrid('instance');
var rec = obj.getColumnByField('EmployeeID').dataSource.filter(function (a) { return a['num'] === val });
return rec[0] ? rec[0]['EmployeeID'] : 1;
},
write: function (e) {
var obj = e.element.closest('.e-grid').ejGrid('instance');
var rec = obj.getColumnByField('EmployeeID').dataSource.filter(function (a) { return a['EmployeeID'] === e.rowdata["EmployeeID"] });
e.element.ejNumericTextbox({
value: rec[0].num || ""
})
}
}, width: 90
},
………………
]
});
});
</script> |