|
$(function () {
$("#Grid").ejGrid({
dataSource: data,
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true },
allowSorting: true,
actionComplete:"complete",
detailsExpand:"expand",
columns: [
{ field: "EmployeeID", headerText: 'Employee ID',isPrimaryKey:true, textAlign: ej.TextAlign.Right, width: 75 },
{
field: "FirstName", headerText: 'First Name', editTemplate: {
create: function () {
return "<input>";
},
read: function (args) {
return args.ejMaskEdit("get_UnstrippedValue");
},
write: function (args) {
args.element.ejMaskEdit({
value: args.rowdata["FirstName"]
});
}
}, textAlign: ej.TextAlign.Left, width: 100 },
],
childGrid: {
dataSource: dataManger2,
queryString: "EmployeeID",
allowPaging: true,
detailsExpand:"expand",
editSettings: {allowEditing:true,allowAdding:true,allowDeleting:true},
detailsTemplate: "#tabGridContents",
detailsDataBound: "detailGridData",
columns: [
{ field: "OrderID", headerText: 'Order ID',isPrimaryKey:true, textAlign: ej.TextAlign.Right, width: 75 },
{ field: "EmployeeID", headerText: 'EmployeeID',textAlign: ej.TextAlign.Right, width: 75 },
{
field: "ShipCity", headerText: 'Ship City', editTemplate: {
create: function () {
return "<input>";
},
read: function (args) {
return args.ejMaskEdit("get_UnstrippedValue");
},
write: function (args) {
args.element.ejMaskEdit({
value: args.rowdata["ShipCity"]
});
}
}, textAlign: ej.TextAlign.Left, width: 100 },
],
},
});
});
var expanded = [];
var flag = true;
function expand(args) {
if (flag) {
expanded.push(args.masterRow[0].rowIndex);
flag = true;
}
}
function complete(args) {
if (args.requestType == "refresh") {
if (expanded.length != 0) {
flag = false;
for (var i = 0; i < expanded.length; i++) {
this.expandCollapse(this.getRowByIndex(expanded[i]).find("td.e-detailrowcollapse"));
}
}
}
}
function update() {
var obj = $("#Grid").ejGrid("instance");
obj.model.childGrid.dataSource = data1; //updating the dataSource of childgrid
$("#Grid").ejGrid("dataSource", newdata); //updating the dataSource of parent grid
} |