var grid = new ej.grids.Grid({
dataSource: data,
toolbar: ['Add', 'Edit', 'Delete'],
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Dialog' },
columns: [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 100, isPrimaryKey: true },
{ field: 'CustomerID', headerText: 'Customer ID', width: 120, visible: false },
{ field: 'Freight', headerText: 'Freight', textAlign: 'Right', editType: 'numericedit', width: 120, format: 'C2' },
{ field: 'ShipCountry', headerText: 'Ship Country', width: 150 }
],
height: 265,
actionBegin: function (args) {
if ((args.requestType === 'beginEdit' || args.requestType === 'add')) {
for (var i = 0; i < this.columns.length; i++) {
if (this.columns[i].field == "CustomerID") {
this.columns[i].visible = true;
}
else if (this.columns[i].field == "ShipCountry") {
this.columns[i].visible = false;
}
}
}
},
actionComplete: function (args) {
if (args.requestType === 'save') {
for (var i = 0; i < this.columns.length; i++) {
if (this.columns[i].field == "CustomerID") {
this.columns[i].visible = false;
}
else if (this.columns[i].field == "ShipCountry") {
this.columns[i].visible = true;
}
}
}
}
});
grid.appendTo('#Grid');|
var grid = new ej.grids.Grid({
dataSource: data,
toolbar: ["Add", "Edit", "Delete"],
editSettings: {
allowEditing: true,
allowAdding: true,
allowDeleting: true,
mode: "Dialog"
},
columns: [
{
field: "OrderID",
headerText: "Order ID",
textAlign: "Right",
width: 100,
isPrimaryKey: true
},
{
field: "CustomerID",
headerText: "Customer ID",
width: 120,
visible: false
},
{
field: "Freight",
headerText: "Freight",
textAlign: "Right",
editType: "numericedit",
width: 120,
format: "C2"
},
{ field: "ShipCountry", headerText: "Ship Country", width: 150 }
],
height: 265,
actionBegin: function (args) {
if (args.requestType === "beginEdit" || args.requestType === "add") {
// change the columns state
for (var i = 0; i < this.columns.length; i++) {
if (this.columns[i].field == "CustomerID") {
this.columns[i].visible = true;
} else if (this.columns[i].field == "ShipCountry") {
this.columns[i].visible = false;
}
}
}
if (args.requestType === "save") {
// reset the columns state
for (var i = 0; i < this.columns.length; i++) {
if (this.columns[i].field == "CustomerID") {
this.columns[i].visible = false;
} else if (this.columns[i].field == "ShipCountry") {
this.columns[i].visible = true;
}
}
}
}
});
grid.appendTo("#Grid");
|
|
var myData = [
{
CustomerID: 2,
child: [{ OrderID: 10, ShipCountry: "Bathurst" }],
OrderID: 3,
Freight: 21
}
];
var grid = new ej.treegrid.TreeGrid({
dataSource: myData,
…..
childMapping: "child",
columns: [
….
{
field: "CustomerID",
visible: false
},
…….
],
…..
actionBegin: function(args) {
if (args.requestType === "beginEdit" || args.requestType === "add") {
for (var i = 0; i < this.columns.length; i++) {
if (this.columns[i].field == "CustomerID") {
this.grid.columns[i].visible = true;
} else if (this.columns[i].field == "ShipCountry") {
this.grid.columns[i].visible = false;
}
}
}
if (args.requestType === "save") {
for (var i = 0; i < this.columns.length; i++) {
if (this.columns[i].field == "CustomerID") {
this.grid.columns[i].visible = false;
} else if (this.columns[i].field == "ShipCountry") {
this.grid.columns[i].visible = true;
}
……..
});
|