DevExtreme jQuery - ODataContext Options
beforeSend
Name | Type | Description |
---|---|---|
url |
The request URL. |
|
async |
Indicates whether the request is asynchronous or synchronous. |
|
method |
The request method ("GET", "POST", "PATCH", or "MERGE"). |
|
timeout |
The request timeout. |
|
params |
Additional parameters. |
|
payload |
The request body; for example, when updating an item, this property holds an object with new values. |
|
headers |
The request headers. |
jQuery
var context = new DevExpress.data.ODataContext({ url: "https://js.devexpress.com/Demos/DevAV/odata/", entities: { Employees: { key: "Employee_ID", keyType: "Int32" }, Customers: { key: "Customer_ID", keyType: "Int32" } }, beforeSend: function (e) { e.params = { "param1": "value1", "param2": "value2" }; e.headers = { "Custom Header": "value" }; } });
Angular
import ODataContext from "devextreme/data/odata/context"; // ... export class AppComponent { context: ODataContext; constructor() { this.context = new ODataContext({ url: "https://js.devexpress.com/Demos/DevAV/odata/", entities: { Employees: { key: "Employee_ID", keyType: "Int32" }, Customers: { key: "Customer_ID", keyType: "Int32" } }, beforeSend: (e) => { e.params = { "param1": "value1", "param2": "value2" }; e.headers = { "Custom Header": "value" }; } }); } }
deserializeDates
Stores can parse date-time values in ISO8601 format (for example, "2016-07-13T16:05:00.000Z"
) or Microsoft format (for instance, "/Date(1198908717056)/"
). In the first case, the store ignores the timezone modifier (usually Z
) when parsing the value. In the second case, the store adds the time-zone offset to the value according to the client's time-zone.
Disabling deserialization may cause filtering issues in widgets bound to the ODataStore. When deserialization is disabled in the store, date-time strings are converted to Date objects at the widget level. When filtering, the widget reverts an entered date-time value to a string based on the dateSerializationFormat option's value and passes the string to the ODataStore for further processing. OData does not support strings which cause filtering to fail.
To prevent these issues, the store's deserializeDates option should be set to true or set the widget's dateSerializationFormat option to null.
entities
The ODataContext creates an ODataStore per entity collection, so you need to use ODataStore options for configuring access to entity collections. In the following code, access to the Employees
and Customers
entity collections is configured, but only Customers
is loaded using the load() method:
jQuery
var context = new DevExpress.data.ODataContext({ url: "https://js.devexpress.com/Demos/DevAV/odata/", entities: { // Configures access to "https://js.devexpress.com/Demos/DevAV/odata/Employees" Employees: { key: "Employee_ID", keyType: "Int32" }, // Configures access to "https://js.devexpress.com/Demos/DevAV/odata/Customers" Clients: { // The collection alias name: "Customers", // The collection name key: "Customer_ID", keyType: "Int32" } } }); context.Clients.load();
Angular
import ODataContext from "devextreme/data/odata/context"; // ... export class AppComponent { context: ODataContext; constructor() { this.context = new ODataContext({ url: "https://js.devexpress.com/Demos/DevAV/odata/", entities: { // Configures access to "https://js.devexpress.com/Demos/DevAV/odata/Employees" Employees: { key: "Employee_ID", keyType: "Int32" }, // Configures access to "https://js.devexpress.com/Demos/DevAV/odata/Customers" Clients: { // The collection alias name: "Customers", // The collection name key: "Customer_ID", keyType: "Int32" } } }); this.context.Clients.load(); } }
errorHandler
A JavaScript Error object extended with the following fields:
Name | Type | Description |
---|---|---|
httpStatus |
The error code. |
|
errorDetails |
Error details. It is an OData error response object for OData-specific errors or a jqXHR object for other errors when you use jQuery. |
|
requestOptions |
Request details. Contains the following fields:
|
jQuery
var context = new DevExpress.data.ODataContext({ // ... errorHandler: function(error) { console.log(error.message); } });
Angular
import ODataContext from "devextreme/data/odata/context"; // ... export class AppComponent { context: ODataContext; constructor() { this.context = new ODataContext({ // ... errorHandler: (error) => { console.log(error.message); } }) } }
filterToLower
Specifies whether to convert string values to lowercase in filter and search requests. Applies to the following operations: "startswith", "endswith", "contains", and "notcontains".
Defaults to the global oDataFilterToLower setting.
When this option is true, the filter expression sent to the server contains a tolower()
function call and a lowercase filter value.
jQuery
var context = new DevExpress.data.ODataContext({ url: "https://js.devexpress.com/Demos/DevAV/odata/", entities: { Employees: { key: "Employee_ID", keyType: "Int32" }, // ... }, filterToLower: true }); var ds = new DevExpress.data.DataSource({ store: context.Employees, filter: ["Employee_Name", "startswith", "Jo"] }); // The filter expression in the request looks like the following: // https://...?filter=startswith(tolower(Employee_Name), 'jo')
Angular
import ODataContext from 'devextreme/data/odata/context'; import DataSource from 'devextreme/data/data_source'; // ... export class AppComponent { context: ODataContext; ds: DataSource; constructor() { this.context = new ODataContext({ url: "https://js.devexpress.com/Demos/DevAV/odata/", entities: { Employees: { key: "Employee_ID", keyType: "Int32" }, // ... }, filterToLower: true }); this.ds = new DataSource({ store: this.context.Employees, filter: ["Employee_Name", "startswith", "Jo"] }); // The filter expression in the request looks like the following: // https://...?filter=startswith(tolower(Employee_Name), 'jo') } }
url
jQuery
var context = new DevExpress.data.ODataContext({ // ... url: "https://js.devexpress.com/Demos/DevAV/odata/", });
Angular
import ODataContext from "devextreme/data/odata/context"; // ... export class AppComponent { context: ODataContext; constructor() { this.context = new ODataContext({ // ... url: "https://js.devexpress.com/Demos/DevAV/odata/", }); } }
See Also
version
If the version is 2, the ODataContext uses the "MERGE" method to send requests; otherwise, it uses "PATCH". Set the method field of the beforeSend function's parameter to override this behavior.
withCredentials
Specifies whether to send cookies, authorization headers, and client certificates in a cross-origin request.
This option's value is passed to the underlying jqXHR object.
Use the beforeSend function to specify custom authorization headers.
If you have technical questions, please create a support ticket in the DevExpress Support Center.