Articles in this section
Category / Section

Server-side API for DataManager operations.

1 min read

The DataManager class helps in binding the Grid queries passed to the server-side. Based on those queries you can perform server-side operation on the Grid data.

The query parameters that help you perform the server-side operations are as follows.

Table 1: Query Parameters

Expand

It is used as OData Expand query.

RequiresCounts

When this property is set as True, the total count of records are included in the result.

Skip

Details regarding current page are skipped.

Take

Used to take required records from data manager.

Sorted

Records return the sorted collection.

Table

It is a data source table name.

Where

Records return the filter collection.

DataManager Operations:

The query parameters are serialized by the DataManager class and the server-side operations such as sorting, filtering, paging are performed by the PerformSorting, PerfomWherFilter, PerformSkip and PerformTake methods.

C#

public ActionResult DataSource(Syncfusion.JavaScript.DataManager dm)
        {
            IEnumerable Data = OrderRepository.GetAllRecords();             
            Syncfusion.JavaScript.DataSources.DataOperations operation = new Syncfusion.JavaScript.DataSources.DataOperations();
                       if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
            {
                Data = operation.PerformSorting(Data, dm.Sorted);
            }
            if (dm.Where != null && dm.Where.Count > 0) //Filtering
            {
                Data = operation.PerformWhereFilter(Data, dm.Where, dm.Where[0].Operator);
            }
                 int count=Data.AsQueryable().Count();
            if (dm.Skip != 0)
            {
                Data = operation.PerformSkip(Data, dm.Skip);
            }
            if (dm.Take != 0)
            {
                Data = operation.PerformTake(Data, dm.Take);
            }
                   return Json(new { result = Data, count = count }, JsonRequestBehavior.AllowGet);
        }

DataOperations Method:

You can also perform the server side operation such as filtering, paging and sorting by using the DataOperations Execute method instead of using the individual methods. The following code example shows you how to use the Execute method in the DataManager.

Table 2: Server side operation order for Execute method

Server side operation Orders

  1. PerformWhereFilter
  1. PerformSearching
  1. PerformSorting
  1. PerformSelect
  1. PerformSkip
  1. PerformTake

C#

public ActionResult DataSource(Syncfusion.JavaScript.DataManager dm)
        {
            IEnumerable Data = OrderRepository.GetAllRecords(); 
            int count=Data.AsQueryable().Count();
            Syncfusion.JavaScript.DataSources.DataOperations operation = new Syncfusion.JavaScript.DataSources.DataOperations();
            Data = operation.Execute(Data, dm);
            return Json(new { result = Data, count = count }, JsonRequestBehavior.AllowGet);
 
        }

MVC

In the following code example is demonstrated the server-side operation using UrlAdaptor.

C#

[Controller]
namespace serversidemvc.Controllers
{
    public class GridController : Controller
    {
        //
        // GET: /Grid/
        public ActionResult GridFeatures()
        {
            return View();
        }
        public ActionResult DataSource(Syncfusion.JavaScript.DataManager dm)
        {
            IEnumerable Data = OrderRepository.GetAllRecords(); 
            int count=Data.AsQueryable().Count();
            Syncfusion.JavaScript.DataSources.DataOperations operation = new Syncfusion.JavaScript.DataSources.DataOperations();
            Data = operation.Execute(Data, dm);
            return Json(new { result = Data, count = count }, JsonRequestBehavior.AllowGet);
        }
[View]
@(Html.EJ().Grid<serversidemvc.OrdersView>("FlatGrid")
         .Datasource(ds => ds.URL("/Grid/DataSource").Adaptor("UrlAdaptor"))
         .AllowFiltering()
         .AllowSorting()    /*Sorting Enabled*/
         .AllowPaging()    /*Paging Enabled*/
         .Columns(col =>
        {
            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
            col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add();
            col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Add();           col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add();
            col.Field("OrderDate").HeaderText("Order Date").TextAlign(TextAlign.Right).Width(80).Format("{0:MM/dd/yyyy}").Add();
            col.Field("ShipCity").HeaderText("Ship City").Width(110).Add();
        }))

ASP

In ASP.NET, the server-side operation is performed by using the WebMethodAdaptor, and the DataManager parameter is set as value.

C#

[Default.aspx]
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <div class="row">
        <div class="col-md-9" style="margin-top: 10px">
            <ej:Grid ID="EmployeesGrid" runat="server" Width="1500px" AllowPaging="true" AllowFiltering="true" AllowSorting="true">
                <DataManager URL="Default.aspx/Data" Adaptor="WebMethodAdaptor" />
                <Columns>
                        <ej:Column Field="OrderID" IsPrimaryKey="true" HeaderText="Order ID" Width="80" />
                        <ej:Column Field="EmployeeID" HeaderText="Employee ID" Width="80" />
                        <ej:Column Field="Freight" HeaderText="Freight" Width="100" EditType="Numeric" />
                        <ej:Column Field="ShipCity" HeaderText="ShipCity" Width="80" />
                    </Columns>
            </ej:Grid>
        </div>
    </div>
</asp:Content>
[Default.aspx.cs]
public partial class _Default : Page
    {   
        protected void Page_Load(object sender, EventArgs e)
        {
                    }
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public static object Data(Syncfusion.JavaScript.DataManager value)
        {
            IEnumerable Data = OrderRepository.GetAllRecords();
            int count = Data.AsQueryable().Count();
            Syncfusion.JavaScript.DataSources.DataOperations operation = new Syncfusion.JavaScript.DataSources.DataOperations();
            Data = operation.Execute(Data, value);
            return new { result = Data, count = count };
        }      
        }

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please  to leave a comment
Access denied
Access denied