|
@Html.EJS().Grid("Grid").DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").UpdateUrl("/Home/Update").InsertUrl("/Home/Insert").RemoveUrl("/Home/Remove").Adaptor("UrlAdaptor"); }).Columns(col =>
{
...
col.Field("EmployeeID").HeaderText("Employee ID").AllowEditing(false).DefaultValue("1").Width("150").Add();
...
}).AllowPaging().Load("load").EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
<script>
function load(args) {
this.childGrid = {
queryString: 'EmployeeID',
dataSource: new ej.data.DataManager({
url: "/Home/ChildDatasource/",
insertUrl: "/Home/ChildInsert/",
updateUrl: "/Home/ChildUpdate/",
removeUrl: "/Home/ChildDelete/",
adaptor: new ej.data.UrlAdaptor()
}),
query: new ej.data.Query().addParams("key", "1"),
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'],
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Dialog' },
columns: [
{ field: 'EmployeeID', headerText: 'Employee ID',isPrimaryKey: true, width: 120 },
{ field: 'FirstName', headerText: 'FirstName', width: 120 },
{ field: 'LastName', headerText: 'LastName', width: 120 }
]
};
}
</script> |
|
...
<script>
function load(args) {
this.childGrid = {
...
query: new ej.data.Query().addParams("key", "1"),
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'],
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Dialog' }, //crud operations in a dialog popup
columns: [
{ field: 'EmployeeID', headerText: 'Employee ID',isPrimaryKey: true, width: 120 }, //columns for childGrid
{ field: 'FirstName', headerText: 'FirstName', width: 120 },
{ field: 'LastName', headerText: 'LastName', width: 120 }
]
};
}
</script> |
|
...
<script>
function load(args) {
this.childGrid = {
...
query: new ej.data.Query().addParams("key", "1"), //any string can be passed to the server side
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'],
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Dialog' }, //crud operations in a dialog popup
columns: [
{ field: 'EmployeeID', headerText: 'Employee ID',isPrimaryKey: true, width: 120 }, //columns for childGrid
{ field: 'FirstName', headerText: 'FirstName', width: 120 },
{ field: 'LastName', headerText: 'LastName', width: 120 }
]
};
}
</script> |
|
...
function load(args) {
this.childGrid = {
queryString: "EmployeeID",
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'],
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' },
columns: [
{ field: 'contatos.name', headerText: 'name', isPrimaryKey: true, width: 120 },
{ field: 'contatos.age', headerText: 'age', width: 120 },
{ field: 'contatos.EmployeeID', headerText: 'ID', width: 120 }
],
load: function () {
var data = [];
data.push(this.parentDetails.parentRowData);
this.dataSource = new ej.data.DataManager({
json: data,
insertUrl: "/Home/Insert/",
updateUrl: "/Home/Update/",
removeUrl: "/Home/Remove/",
adaptor: new ej.data.RemoteSaveAdaptor()
})
}
}
}
... |
|
...
function begin(args) {
if ((args.requestType === 'beginEdit' || args.requestType === 'add')) {
for (var i = 0; i < this.columns.length; i++) { //based on your columns
if (this.columns[i].field == "EmployeeID" || this.columns[i].field == "Freight" || this.columns[i].field == "ShipCountry") {
this.columns[i].visible = true;
}
}
}
}
function complete(args) {
if (args.requestType === 'save') {
for (var i = 0; i < this.columns.length; i++) {
if (this.columns[i].field == "EmployeeID" || this.columns[i].field == "Freight" || this.columns[i].field == "ShipCountry") {
this.columns[i].visible = false;
}
}
}
}
... |
|
[.cs]
...
reg = "Registro";
ViewBag.reg = reg;
...
[.cshtml]
...
var str = @Html.Raw(Json.Encode(ViewBag.reg));
console.log(str);
... |
|
@Html.EJS().Grid("Grid").DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").UpdateUrl("/Home/Update").InsertUrl("/Home/Insert").RemoveUrl("/Home/Remove").Adaptor("UrlAdaptor"); }).Columns(col =>
{
...
}).AllowPaging().DetailTemplate("#child").DetailDataBound("load").EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
<script id="child" type="text/x-template">
<div id="gridparent"></div>
</script>
<script>
class CustomAdaptor extends ej.data.UrlAdaptor {
processResponse(data, ds, query, xhr, request, changes) {
if (!ej.base.isNullOrUndefined(data.message)) {
alert(data.message);
...
}
if (!ej.base.isNullOrUndefined(data.data))
return data.data;
else
return data;
}
}
function load(args) {
var rowData = args.data;
var childGrid = new ej.grids.Grid({
dataSource: new ej.data.DataManager({
url: "/Home/UrlDatasource/",
insertUrl: "/Home/Insert/",
updateUrl: "/Home/Update/",
removeUrl: "/Home/Remove/",
adaptor: new CustomAdaptor()
}),
load: function (args) {
this.query = new ej.data.Query().where("EmployeeID", "equal", rowData['contatos']['EmployeeID']); //filtering operation to show related data in childGrid
},
actionBegin: function (args) {
if (args.requestType == 'save') {
args.data.EmployeeID = args.data.contatos.EmployeeID;
}
},
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'],
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' },
columns: [
{ field: 'OrderID', headerText: 'Order ID', isPrimaryKey: true, width: 120 },
{ field: 'contatos.EmployeeID', headerText: 'Employee ID', width: 120 },
{ field: 'contatos.name', headerText: 'name', width: 120 },
{ field: 'contatos.age', headerText: 'age', width: 120 }
]
});
childGrid.appendTo(args.detailElement.querySelector('#gridparent'));
}
</script> |
|
...
public ActionResult Update(CRUDModel myObject)
{
...
var msg = "Updated";
return Json(new { data = myObject.Value, message = msg });
}
public ActionResult Insert(OrdersDetails value)
{
var msg = "Inserted";
OrdersDetails.BindData().Insert(0, value);
return Json(new { data = value, message = msg });
}
public ActionResult Remove(int key)
{
orddata.Remove(orddata.Where(or => or.OrderID == key).FirstOrDefault());
var msg = "deleted";
var dataa = new { result = orddata, count = orddata.Count };
return Json(new { data = dataa, message = msg});
}
... |
|
[.cshtml]
...
class CustomAdaptor extends ej.data.UrlAdaptor {
processResponse(data, ds, query, xhr, request, changes) {
if (!ej.base.isNullOrUndefined(data.message)) {
setTimeout(() => {
var toastObj = document.getElementById('element').ej2_instances[0];
toastObj.target = document.body;
toastObj.content = data.message;
toastObj.show();
}, 500);
}
if (!ej.base.isNullOrUndefined(data.data))
return data.data;
else
return data;
}
}
... |
|
...
<script>
...
function load(args) {
var rowData = args.data;
var childGrid = new ej.grids.Grid({
...
load: function (args) {
this.query = new ej.data.Query().where("contatos.EmployeeID", "equal", rowData['EmployeeID']); //filtering operation to show related data in childGrid
//contator.EmployeeID is the childGrid field name which shares identical data with the parent EmployeeID- “contatos.cliente_id”
},
actionBegin: function (args) {
if (args.requestType == 'save') {
args.data.EmployeeID = args.data.contatos.EmployeeID;
}
},
...
});
childGrid.appendTo(args.detailElement.querySelector('#gridparent'));
}
</script> |
Json Property and set adaptor type as RemoteSaveAdaptor to the Adaptor Property of Grid DataManager. Please find the code example |
[Index.cshtml]
@Html.EJS().Grid("Grid").DataSource(dataManager =>{dataManager.Json(ViewBag.dataSource)
.InsertUrl("/Home/Insert").RemoveUrl("/Home/Delete").UpdateUrl("/Home/Update").Adaptor("RemoteSaveAdaptor");})
.EditSettings(e => { e.AllowAdding(true).AllowEditing(true).AllowDeleting(true); })
.Columns(col => {
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("30%").Add();
...
}).Render()
[HomeController.cs]
//update the record
public ActionResult Update(OrdersDetails value)
{
...
return Json(value);
}
//insert the record
public ActionResult Insert(OrdersDetails value)
{
...
return Json(new { data = value });
}
//Delete the record
public ActionResult Delete(int key)
{
...
return Json(data);
}
|
|
<script id="child" type="text/x-template">
<div id="gridparent"></div> //id of the child grid
</script>
|
|
...
function load(args) {
var rowData = args.data;
var childGrid = new ej.grids.Grid({
dataSource: new ej.data.DataManager({
...
columns: [
...
],
locale: "pt-BR"
});
var elem = document.createElement('div');
elem.id = "childGrid-" + args.data.EmployeeID; //you can create div’s with unique ids and append the grid.
childGrid.appendTo(elem);
args.detailElement.querySelector('#gridparent').appendChild(elem);
}
...
|
|
document.getElementById(“childGrid-1”).ej2_instances[0];
|
|
...}).AllowPaging().Locale("pt-BR").DetailTemplate("#child").DetailDataBound("load").EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
...
<script>
ej.base.setCulture("pt-BR")
ej.base.L10n.load({
'pt-BR': {
grid: {
"Add": "adicionar"
}
}
});
...
function load(args) {
var rowData = args.data;
var childGrid = new ej.grids.Grid({
dataSource: new ej.data.DataManager({
...
}),
...
columns: [
...
],
locale: "pt-BR"
});
childGrid.appendTo(args.detailElement.querySelector('#gridparent'));
}
|