@*adds set of columns in single shot triggers myBatchDataSourceUrl one time*@
@Html.EJ().Button("btn1").Text("AddBulk").ClientSideEvents(events => events.Click("click1"));
@*adds each column one by one triggers the myBatchDataSourceUrl same number of time*@
@Html.EJ().Button("btn2").Text("AddOnebyOne").ClientSideEvents(events => events.Click("click2"));
@(Html.EJ().Grid<object>("FlatGrid")
.AllowPaging()
.Datasource(ds => ds.URL("/Home/DataSource").Adaptor(AdaptorType.UrlAdaptor))
.Columns(col =>
{
. . . .
})
)
<script>
function click1(args) {
var gridObj = $("#FlatGrid").ejGrid("instance");
if (gridObj.model.currentViewData.length > 0) {
var fields = [];
for (var field in gridObj.model.currentViewData[0]) {
if (field.indexOf("ID") >= 0) {
fields.push(field);
}
}
//array of strings/field Names pushed into the fields
gridObj.columns(fields, "add");//adds set of columns in single shot it is recommended
}
}
function click2(args) {
var gridObj = $("#FlatGrid").ejGrid("instance");
if (gridObj.model.currentViewData.length > 0) {
for (var field in gridObj.model.currentViewData[0]) {
if (field.indexOf("ID") >= 0) {
// this method will send multiple request
gridObj.columns(field, "add");
}
}
}
}
</script>
|
var obj = $("#FlatGrid").ejGrid("instance");
obj.columns("EmployeeID", "remove")
//or
var obj = $("#FlatGrid").ejGrid("instance");
obj.columns(["OrderID", "EmployeeID"], "remove")//recommended for more than one column |
<div class="label1">
Master Grid
</div>
@(Html.EJ().Grid<EmployeeView>("MasterGrid")
.Datasource(ds => ds.URL("/Home/masterData").Adaptor(AdaptorType.UrlAdaptor))
.SelectedRowIndex(0)
. . .
.ClientSideEvents(eve => { eve.RowSelected("rowSelected"); })
)
<div class="label1">
Detail Grid
</div>
@(Html.EJ().Grid<OrdersView>("DetailGrid")
. . .
.ClientSideEvents(e => e.ActionComplete("onActionComplete"))
)
<script>
var flag = false;
function rowSelected(args) {//master Grid
flag = true;
var employeeID = args.data.EmployeeID;
$("#DetailGrid").ejGrid({
query: new ej.Query().where("EmployeeID", "equal", employeeID)
});
var gridObj = $("#DetailGrid").ejGrid("instance");
gridObj.dataSource(ej.DataManager({//use dataSource method update the Grid Records - Recommended
url: "/Home/childData",
adaptor: new ej.UrlAdaptor()
}))
}
function onActionComplete(args) {//child Grid actionComplete event
//flag allows the Grid to add the columns only after rowSelection
if (args.requestType == "refresh" && !ej.isNullOrUndefined(this.model.currentViewData) && flag) {
flag = false;
if (this.model.currentViewData.length > 0) {
var fields = [];
for (var field in this.model.currentViewData[0]) {
if (field.indexOf("ID") >= 0) {
fields.push(field);
}
}
this.columns(fields, "add");
}
}
}
</script> |