How to view and Postback the QueryBuilder String to the Controller?
The DataSource operations can be performed in the Controller side by using the DataManager Query property. The Query property is used to perform the data operation in ActionResult, but to perform the server side data operation, URL Adapter and URL DataSource binding should be used. The following are the DataManager Query properties:
Queries | Description |
Expand | It is an OData Expand query. |
RequiresCounts | It is the total count of the records. |
Skip | Details regarding current page is skipped. |
Take | Used to take the required records from the data manager. |
Search | Result to match the specified search expression. |
Group | It is used to return the grouped details of the Grid. |
Select | Used to select user required properties that are available in the DataSource. |
Sorted | Entries return in the ascending or descending order when the property is sorted. |
Table | It is a DataSource table. |
Where | It is used to extract only those records that fulfill the specified criteria. |
The code example for URL DataSource binding in the Grid:
CSHTML
.Datasource(ds => ds.URL("Home/data").InsertURL("Home/Add").UpdateURL("Home/Update").RemoveURL("Home/Delete").Adaptor("UrlAdaptor"))
The following example shows the skip and take operation in the Controller. In this sample, records are taken in the load on demand from data manager and the details regarding the current page is passed by using skip.
MVC
[razor] @(Html.EJ().Grid<Sample_129354.OrdersView>("FlatGrid") .Datasource(ds => ds.URL("Home/data").InsertURL("Home/Add").UpdateURL("Home/Update").RemoveURL("Home/Delete").Adaptor("UrlAdaptor")) .AllowPaging() .AllowGrouping() .AllowFiltering() .AllowSorting() .Columns(col => { col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Add(); col.Field("ShipName").HeaderText("ShipName").TextAlign(TextAlign.Left).Width(75).Add() col.Field("ShipCity").HeaderText("Ship City").Width(110).Add(); })) [controller] public class HomeController : Controller { public ActionResult data(DataManager dm ) { var dataSource = OrderRespositary.GetAllRecords(); DataResult ds = new DataResult(); ds.result = dataSource.Skip(dm.Skip).Take(dm.Take); ds.count = dataSource.Count; return Json(ds, JsonRequestBehavior.AllowGet); } public class DataResult { public IEnumerable result { get; set; } public int count { get; set; } } }
DataSource operations