// Grid rendering code
@(Html.EJ().Grid<object>("dropDown").Datasource(datasource => datasource.URL("/CCM/JobParameters").Offline(true)) // in place of url you can bind the server side method name
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })
.AllowSorting().AllowPaging().PageSettings(page => page.PageSize(15)).IsResponsive()
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.Update);
items.AddTool(ToolBarItems.Cancel);
});
. . . .
}))
// dropdown change event
function drpvaluechange(args) {
var gridObj = $("#dropDown").ejGrid("data");
gridObj.filterColumn("OrderID", "equal", "10248", "and", true);
} |
var gridObj = $("#Grid").data("ejGrid"); //Grid denotes the grid id |
<div>
@(Html.EJ().DropDownList("DropDownList1").Datasource((IEnumerable<object>)ViewData["LocalDataSource"]).DropDownListFields(Df => Df.Text("Text").Value("value")).ClientSideEvents(e=>e.Change("jobChanged")))
</div>
<br>
<div>
@(Html.EJ().Grid<object>("paramGrid")
.Datasource(ds => ds.URL("UrlDataSource").UpdateURL("UrlUpdate").InsertURL("UrlInsert").RemoveURL("UrlDelete")
.Adaptor(AdaptorType.UrlAdaptor)).
……………..
.Columns(col =>
{
…………
}))
</div>
<script>
function jobChanged(args) {
var selectedItemId = args.model.dataSource[args.itemId].value;
var gridObj = $("#paramGrid").ejGrid("instance"); // use the Grid id
var query = ej.Query().addParams("jobid", selectedItemId);
var dataManager = ej.DataManager({ url: '@Url.Action("GetGridData", "Grid")', adaptor: new ej.UrlAdaptor() });
// executing query
var promise = dataManager.executeQuery(query);
promise.done(function (e) {
gridObj.dataSource(e.result); // using datasource method refer the grid data.
});
};
</script>
Server Side
public ActionResult GetGridData(int jobid)
{
var result = OrderRepository.GetAllRecords().Where(e => e.EmployeeID == jobid).ToList();
return Json(result, JsonRequestBehavior.AllowGet);
}
public ActionResult UrlDataSource(DataManager dm)
{
………..
}
public ActionResult UrlUpdate(EditableOrder value)
{
…
}
public ActionResult UrlInsert(EditableOrder value)
{
…..
}
public ActionResult UrlDelete(int key)
{
……….
}
|
@(Html.EJ().Grid<object>("paramGrid")
.Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.dataSource).UpdateURL("NormalUpdate")
.InsertURL("NormalInsert").RemoveURL("NormalDelete").Adaptor(AdaptorType.RemoteSaveAdaptor))
…………
.ToolbarSettings(toolbar =>
{
………….
}).Columns(col =>
{
…………….
}))
</div>
public ActionResult GridFeatures()
{
………
var DataSource = OrderRepository.GetAllRecords();
ViewBag.datasource = DataSource;
return View();
}
|
@(Html.EJ().Grid<object>("GridParameters")
.Datasource(datasource => datasource.Json(Model.ParameterList)
.UpdateURL("/Grid/Update").InsertURL("/Grid/Insert").RemoveURL("/Grid/Delete")
.Adaptor(AdaptorType.RemoteSaveAdaptor))
.EditSettings(edit => { edit.AllowAdding(true).AllowDeleting(true).AllowEditing(true); })
.AllowResizeToFit()
.Query("ej.Query().addParams('x','').addParams('y','')")
.AllowSorting().AllowPaging().PageSettings(page => page.PageSize(20)).IsResponsive()
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.Update);
items.AddTool(ToolBarItems.Cancel);
});
}).Columns(col =>
{
…………………………………………………………………..
}).ClientSideEvents(evt => evt.EndEdit("OnToolbarClick").ActionBegin("begin")))
<script type="text/javascript">
function begin(args){
if (args.requestType == "save") {
args.model.query._params[0].value = args.rowData.ParameterName;
args.model.query._params[1].value = args.rowData.ParameterValue;
}
}
</script>
|
|