How to pass additional parameter when using DataManager in grid
This knowledge base explains the way how to pass additional parameter when using DataManager in grid.
We can have achieved it by using addParams method of ejQuery.
RAZOR
<ej-grid id="FlatGrid" allow-paging="true" action-begin="begin"> <e-datamanager url="/Home/DataSource" adaptor="UrlAdaptor"/> <e-columns> <e-column field="OrderID" header-text="Order ID" is-primary-key="true" text-align="Right" width="75"></e-column> <e-column field="EmployeeID" header-text="Employee ID" text-align="Right" width="75"></e-column> <e-column field="CustomerID" header-text="Customer ID" text-align="Right" width="75"></e-column> <e-column field="Ship City" header-text="Ship City" text-align="Right" width="75"></e-column> </e-columns> </ej-grid>
JS
In “action-begin” event of grid we have passed the additional parameter value to the server side (Controller side) using addParams method of ejQuery.
<script type="text/javascript"> function begin(args) { args.model.query.addParams("ID", 10248); } </script>
In server side we have inherited and shown the additional parameter value in Syncfusion DataManager class itself.
C#
public class Test : DataManager //inherit the class to show age as property of DataManager { public int ID { get; set; } }
C#
Bind the data manager value using the inherited class name “Test”
public IActionResult DataSource([FromBody]Test dm) { IEnumerable Result = _context.Orders.Take(100).ToList(); var count = _context.Orders.AsQueryable().Count(); DataOperations operation = new DataOperations(); DataResult result = new DataResult(); if (dm.Skip != 0) { Result = operation.PerformSkip(Result, dm.Skip); } if (dm.Take != 0) { Result = operation.PerformTake(Result, dm.Take); } result.result = Result; result.count = count; return Json(result) } public class DataResult { public IEnumerable result { get; set; } public int count { get; set; } }
Figure 1: Additional parameter in DataManager class