<h3>Master Grid</h3>
@(Html.EJ().Grid<EmployeeView>("MasterGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource1)
. .. .
. . . .
.ClientSideEvents(eve => { eve.RowSelected("rowSelected"); })
)
<h3>Details Grid</h3>
@(Html.EJ().Grid<OrdersView>("DetailGrid")
. ..
. . .
)
<script>
function rowSelected(args) {
var EmpID = args.data["EmployeeID"];
//use DataManager with UrlAdaptor
var dataManager = ej.DataManager({
url: "/Home/DataSource",
adaptor: new ej.UrlAdaptor()
});
//Generate Query
var query = ej.Query().where(ej.Predicate('EmployeeID', ej.FilterOperators.equal, EmpID, true)
.and('OrderDate', ej.FilterOperators.lessThanOrEqual, new Date(), true));
var execute = dataManager.executeQuery(query) // executing query
.done(function (e) {
var gridObj = $("#DetailGrid").ejGrid("instance");
//update the Records in done method of the DataManager
gridObj.dataSource(ej.DataManager(ej.parseJSON(e.result)));
});
}
</script>
public class HomeController : Controller
{
public static DataManager query = new DataManager();
public ActionResult DataSource(DataManager dm) {
//save the query for exporing purpose
query = dm;
IEnumerable data = OrderRepository.GetAllRecords().ToList();
DataOperations dp = new DataOperations();
//filter the records based on the DataManager dm query and return
//So you no need to filter in the client end
data = dp.PerformWhereFilter(data, dm.Where, dm.Where[0].Condition);
return Json(data, JsonRequestBehavior.AllowGet);
}
public void ExportToExcel(string GridModel)
{
ExcelExport exp = new ExcelExport();
IEnumerable DataSource = OrderRepository.GetAllRecords().ToList();
DataOperations dp = new DataOperations();
//use the public query to filter the data
DataSource = dp.PerformWhereFilter(DataSource, query.Where, query.Where[0].Condition);
GridProperties obj = ConvertGridObject(GridModel);
exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron");
}
} |