DataManager uses adaptors to process data. There are three types of adaptors in DataManager. They are
JSON Adaptor
URL Adaptor
OData Adaptor
JSON Adaptor
JSONAdaptor is used to process JSON data. It contains methods to process the given JSON data based on the queries. The following code example illustrates on how to use JSONAdaptor.
JSONAdaptor has the following unique in-built methods,
Properties
Parameters
Description
processQuery(ds, query)
dm
Object
ej.DataManager object
query
ej.Query
Sets the default query for the data source
Used to prepare query string for the request data
processResponse(data, ds, query, xhr)
data
Object
JSON data or JSON array
ds
Object
ej.DataManager object
query
ej.Query
Sets the default query for the data source
xhr
Object
XMLHTTPRequest object
Used to precess the response which is return from the Data Source
insert(dm, data)
data
Object
JSON data or JSON array
dm
Object
ej.DataManager object
Inserts a data item in the data table.
remove(dm, keyField, value, tableName)
dm
Object
ej.DataManager object
keyField
String
KeyColumn to find the data
String
Object
Specified value for the keyField
tableName
String
Name of the source table
It is used to remove the data from the dataSource
update(dm, keyField, value, tableName)
dm
Object
ej.DataManager object
keyField
String
KeyColumn to find the data
String
Object
Specified value for the keyField
tableName
String
Name of the source table
Updates existing record and saves the changes to the table..
publicpartialclassDataManager:System.Web.UI.Page{List<Orders>order=newList<Orders>();protectedvoidPage_Load(objectsender,EventArgse){BindDataSource();}privatevoidBindDataSource(){intcode=10000;for(inti=1;i<10;i++){order.Add(newOrders(code+1,"TOMSP",i+0,2.3*i,"Münster"));order.Add(newOrders(code+2,"HANAR",i+2,3.3*i,"Rio de Janeiro"));order.Add(newOrders(code+3,"VICTE",i+1,4.3*i,"Lyon"));order.Add(newOrders(code+4,"VINET",i+3,5.3*i,"Reims"));order.Add(newOrders(code+5,"SUPRD",i+4,6.3*i,"Charleroi"));code+=5;}this.FlatData.Json=order;this.OrdersGrid.DataBind();} [Serializable]publicclassOrders{publicOrders(){}publicOrders(longOrderId,stringCustomerId,intEmployeeId,doubleFreight,stringShipCity){this.OrderID=OrderId;this.CustomerID=CustomerId;this.EmployeeID=EmployeeId;this.Freight=Freight;this.ShipCity=ShipCity;}publiclongOrderID{get;set;}publicstringCustomerID{get;set;}publicintEmployeeID{get;set;}publicdoubleFreight{get;set;}publicstringShipCity{get;set;}}}
The result of above code example is illustrated as follows.
URL Adaptor
URL Adaptor of DataManager can be used when you want to use remote service to retrieve data. It interacts with server-side for all DataManager Queries and CRUD operations. Now, in the following code example the data is retrieved from MVC Controller.
UrlAdaptor has the following unique in-built methods,
Properties
Parameters
Description
processQuery(dm, query, hierarchyFilters)
dm
Object
ej.DataManager object
query
ej.Query
Sets the default query for the data source
hierarchyFilters
ej.Query
The hierarchical query can be provided by using the hierarchical function.
The result of the above code example is illustrated as follows.
WebMethod Adaptor
The WebMethod Adaptor is used to bind data source from remote services and code behind methods. It can be enabled in Grid using Adaptor property of DataManager as WebMethodAdaptor.
For every operations, an AJAX post will be send to the specified data service.
When using WebMethodAdaptor, grid actions such as Paging, Filtering and Sorting should be handled at the server side itself. We have DataOperation class to handle the server side operations. Refer to the kb link.
WebMethod Adaptor supports Model Binding, using DataManager class, for the Grid queries, such as sort, paging queries, etc.,
WebMethodAdaptor has the following unique in-built methods,
Properties
Parameters
Description
processQuery(dm, query, hierarchyFilters)
dm
Object
ej.DataManager object
query
ej.Query
Sets the default query for the data source
hierarchyFilters
ej.Query
The hierarchical query can be provided by using the hierarchical function.
<asp:Contentrunat="server"ID="Content1"ContentPlaceHolderID="MainContent"><ej:DataManagerID="FlatData"runat="server"URL="Default.aspx/DataSource"CrossDomain="true"Adaptor="WebMethodAdaptor"/><ej:GridID="OrdersGrid"runat="server"DataManagerID="FlatData"Query ="new ej.Query().select(['OrderID', 'CustomerID', 'EmployeeID', 'ShipCity', 'Freight']).take(5)"><Columns><ej:ColumnField="OrderID"HeaderText="Order ID"IsPrimaryKey="True"TextAlign="Right"Width="75"/><ej:ColumnField="CustomerID"HeaderText="Customer ID"Width="75"/><ej:ColumnField="EmployeeID"HeaderText="Employee ID"Width="75"/><ej:ColumnField="ShipCity"HeaderText="Ship City"Width="75"/><ej:ColumnField="Freight"HeaderText="Freight"Width="75"/></Columns></ej:Grid></asp:Content>
namespace EJGrid
{
public partial class _Default : Page
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static object DataSource(DataManager value)
{
IEnumerable data = OrderRepository.GetAllRecords();
var count = data.AsQueryable().Count();
DataOperations ds = new DataOperations();
data = ds.Execute(data, value);
return new { result = data, count = count };
}
}
}
NOTE
The data parameter name must be “value”
OData Adaptor
OData Adaptor that is extended from URL Adaptor, is used for consuming data through OData Service. You can use the following code example to use OData adaptor.
ODataAdaptor has the following unique in-built methods,
Result of the above code example is illustrated as follows.
RemoteSave Adaptor
RemoteSaveAdaptor, extended from JsonAdaptor of DataManager, is used for binding local data and performs all DataManager queries in client-side. It interacts with server-side only for CRUD operations to pass the modified records. Refer to the following code example.
RemoteSaveAdaptor has the following unique in-built methods,
Properties
Parameters
Description
insert(dm, data, tableName, query)
data
Object
JSON data or JSON array
dm
Object
ej.DataManager object
tableName
String
Name of the source table
query
ej.Query
Sets the default query for the data source
Inserts a data item in the data table.
remove(dm, keyField, value, tableName, query)
dm
Object
ej.DataManager object
keyField
String
KeyColumn to find the data
String
Object
Specified value for the keyField
tableName
String
Name of the source table
query
ej.Query
Sets the default query for the data source
It is used to remove the data from the dataSource
update(dm, keyField, value, tableName, query)
dm
Object
ej.DataManager object
keyField
String
KeyColumn to find the data
String
Object
Specified value for the keyField
tableName
String
Name of the source table
query
ej.Query
Sets the default query for the data source
Updates existing record and saves the changes to the table..
publicpartialclassDataManager:System.Web.UI.Page{List<Orders>order=newList<Orders>();protectedvoidPage_Load(objectsender,EventArgse){BindDataSource();}privatevoidBindDataSource(){intcode=10000;for(inti=1;i<10;i++){order.Add(newOrders(code+1,"TOMSP",i+0,2.3*i,"Münster"));order.Add(newOrders(code+2,"HANAR",i+2,3.3*i,"Rio de Janeiro"));order.Add(newOrders(code+3,"VICTE",i+1,4.3*i,"Lyon"));order.Add(newOrders(code+4,"VINET",i+3,5.3*i,"Reims"));order.Add(newOrders(code+5,"SUPRD",i+4,6.3*i,"Charleroi"));code+=5;}this.FlatData.Json=order;this.OrdersGrid.DataBind();} [Serializable]publicclassOrders{publicOrders(){}publicOrders(longOrderId,stringCustomerId,intEmployeeId,doubleFreight,stringShipCity){this.OrderID=OrderId;this.CustomerID=CustomerId;this.EmployeeID=EmployeeId;this.Freight=Freight;this.ShipCity=ShipCity;}publiclongOrderID{get;set;}publicstringCustomerID{get;set;}publicintEmployeeID{get;set;}publicdoubleFreight{get;set;}publicstringShipCity{get;set;}}}
Result of the above code example is illustrated as follows.
Custom Adaptor
Custom adaptor is a key technique to customize adaptors in DataManager. Normally ej.Adaptor is base class for all the adaptors. Therefore, first inherit ej.Adaptor to develop customized one and then you can override the functionality in custom adaptor with base class. Refer to the following code example.
<asp:Contentrunat="server"ID="Content1"ContentPlaceHolderID="MainContent"><ej:DataManagerID="FlatData"runat="server"/><ej:GridID="OrdersGrid"runat="server"DataManagerID="FlatData"ClientSideEventsLoad="OnLoad"/><Columns><ej:ColumnField="OrderID"HeaderText="Order ID"IsPrimaryKey="True"TextAlign="Right"Width="75"/><ej:ColumnField="CustomerID"HeaderText="Customer ID"Width="75"/><ej:ColumnField="EmployeeID"HeaderText="Employee ID"Width="75"/><ej:ColumnField="ShipCity"HeaderText="Ship City"Width="75"/><ej:ColumnField="Freight"HeaderText="Freight"Width="75"/></Columns></ej:Grid></asp:Content><asp:ContentID="Content2"ContentPlaceHolderID="ScriptSection"runat="server"><scripttype="text/javascript">$(function(){// Document is ready.//new custom adaptor implementation//able to implement more option in custom adaptor other than insertvarcustomAdaptor=newej.Adaptor().extend({insert:function(dm,data){returndm.dataSource.json.push(data);},processQuery:ej.JsonAdaptor.prototype.processQuery// reused process query from json adaptor});window.FlatData.Adaptor=newcustomAdaptor()window.FlatData.insert({OrderID:10240,CustomerID:"HANAR",EmployeeID:3,ShipCity:"Reims",Freight:"23.4"});window.FlatData.insert({OrderID:10241,CustomerID:"HANAR",EmployeeID:2,ShipCity:"Reims",Freight:"21.4"});window.FlatData.insert({OrderID:10242,CustomerID:"VINET",EmployeeID:5,ShipCity:"Lyon",Freight:"13.4"});varobj=$("#MainContent_OrdersGrid").ejGrid("instance");obj.dataSource(window.FlatData.executeLocal(newej.Query().take(7)));})</script></asp:Content>
Using Custom Adaptor, you can override the existing method of Extended Adaptor,
Properties
Description
beforeSend
Custom headers can be set using pre-request callback beforeSend, by using the setRequestHeader method can be used to modify the XMLHTTPRequest
processQuery
Used to prepare query string for the request data
processResponse
Used to precess the response which is return from the Data Source
insert
The insert method of the data manager is used to add a new record to the table
remove
The remove action submits the data items that should be deleted
update
The update method is used to update the modified changes made to a record in the data source of the DataManager.
Result of above code example is as follows.
Cache Adaptor
Cache Adaptor is used to cache the data of the visited pages. It prevents new requests for the previously visited pages. It can be enabled by using the enableCaching property. You can configure cache page size and duration of caching by using cachingPageSize and timeTillExpiration properties of the ej.DataManager.
CacheAdaptor has the following unique in-built methods,
Properties
Parameters
Description
processQuery(dm, query, hierarchyFilters)
dm
Object
ej.DataManager object
query
ej.Query
Sets the default query for the data source
hierarchyFilters
ej.Query
The hierarchical query can be provided by using the hierarchical function.
<asp:Contentrunat="server"ID="Content1"ContentPlaceHolderID="MainContent"><ej:DataManagerrunat="server"ID="FlatData"URL="Default.aspx/Data"Adaptor="CacheAdaptor"/><ej:GridID="OrdersGrid"runat="server"DataManagerID="FlatData"Query ="new ej.Query().select(['OrderID', 'CustomerID', 'EmployeeID', 'ShipCity', 'Freight']).take(5)"><Columns><ej:ColumnField="OrderID"HeaderText="Order ID"IsPrimaryKey="True"TextAlign="Right"Width="75"/><ej:ColumnField="CustomerID"HeaderText="Customer ID"Width="75"/><ej:ColumnField="EmployeeID"HeaderText="Employee ID"Width="75"/><ej:ColumnField="ShipCity"HeaderText="Ship City"Width="75"/><ej:ColumnField="Freight"HeaderText="Freight"Width="75"/></Columns></ej:Grid></asp:Content>
public partial class DataManager : System.Web.UI.Page
{
List<Orders> order = new List<Orders>();
protected void Page_Load(object sender, EventArgs e)
{
BindDataSource();
}
private void BindDataSource()
{
int code = 10000;
for (int i = 1; i <10;i++){order.Add(newOrders(code+1,"TOMSP",i+0,2.3*i,"Münster"));order.Add(newOrders(code+2,"HANAR",i+2,3.3*i,"RiodeJaneiro"));order.Add(newOrders(code+3,"VICTE",i+1,4.3*i,"Lyon"));order.Add(newOrders(code+4,"VINET",i+3,5.3*i,"Reims"));order.Add(newOrders(code+5,"SUPRD",i+4,6.3*i,"Charleroi"));code+=5;}this.FlatData.Json =order;this.OrdersGrid.DataBind();}[Serializable]publicclassOrders{publicOrders(){}publicOrders(longOrderId,stringCustomerId,intEmployeeId,doubleFreight,stringShipCity){this.OrderID =OrderId;this.CustomerID =CustomerId;this.EmployeeID =EmployeeId;this.Freight =Freight;this.ShipCity =ShipCity;}publiclongOrderID{get;set;}publicstringCustomerID{get;set;}publicintEmployeeID{get;set;}publicdoubleFreight{get;set;}publicstringShipCity{get;set;}}}
Properties
Description
TimeTillExpiration
Specifies the duration of cached pages in milliseconds
CachingPageSize
A number of pages to be cached
Help us improve this page
Please provide additional information
Please provide additional information
Please provide additional information
Please provide additional information
Please provide additional information
Please provide additional information
×
Syncfusion ASP.NET Web Forms
The Syncfusion ASP.NET Web Forms product was officially marked as a retired product with the 2023 Volume 2 release. Support for the retired products will be defined in Syncfusion Product Life Cycle. Using the latest Blazor or ASP.NET Core is recommended for new web application development. You can also visit the Blazor documentation and demo links for additional information, such as Blazor documentation and Blazor demos.