DevExtreme Angular - ODataStore Methods
This section describes the methods that control the ODataStore.
byKey(key)
Gets a data item with a specific key.
A Promise that is resolved after the data item is loaded. It is a native Promise or a jQuery.Promise when you use jQuery.
- import ODataStore from "devextreme/data/odata_store";
- // ...
- export class AppComponent {
- singleKeyStore: ODataStore;
- compositeKeyStore: ODataStore;
- constructor() {
- // The key consists of a single data field
- this.singleKeyStore = new ODataStore({
- key: "field1",
- // ...
- });
- // Gets the data item with "field1" being equal to 1
- this.singleKeyStore.byKey(1).then(
- (dataItem) => { /* Process the "dataItem" here */ },
- (error) => { /* Handle the "error" here */ }
- );
- // The key consists of several data fields
- this.compositeKeyStore = new ODataStore({
- key: [ "field1", "field2" ],
- // ...
- });
- // Gets the data item with both "field1" and "field2" being equal to 1
- this.compositeKeyStore.byKey({
- field1: 1,
- field2: 1
- }).then(
- (dataItem) => { /* Process the "dataItem" here */ },
- (error) => { /* Handle the "error" here */ }
- );
- };
- }
byKey(key, extraOptions)
Gets an entity with a specific key.
An entity's key value.
Additional properties.
| Name | Type | Description |
|---|---|---|
| expand | | | The names of the navigation properties to be loaded simultaneously with the entity (see OData - Associations). |
| select | | | One or more fields to select from the entity. |
A Promise that is resolved after the entity is loaded. It is a native Promise or a jQuery.Promise when you use jQuery.
In the following code, the byKey method loads the product with ID 1 along with the "Category" navigation property:
- import ODataStore from "devextreme/data/odata/store";
- // ...
- export class AppComponent {
- store: ODataStore;
- constructor() {
- this.store = new ODataStore({
- // ...
- key: "Product_ID"
- });
- this.store.byKey(1, { expand: "Category" }).then(
- (dataItem) => { /* Process the "dataItem" here */ },
- (error) => { /* Handle the "error" here */ }
- );
- };
- }
createQuery(loadOptions)
Creates a Query for the OData endpoint.
An object containing the expand, requireTotalCount, and customQueryParams properties.
- import ODataStore from "devextreme/data/odata/store";
- // ...
- export class AppComponent {
- store: ODataStore;
- constructor() {
- this.store = new ODataStore({
- // ODataStore is configured here
- });
- this.query = this.store.createQuery({ expand: "propertyName" });
- };
- }
See Also
insert(values)
In the following code, dataObj is a data object added to the database and returned from the server. If the server returns nothing or the store works with local data, dataObj contains the data object passed to the insert method.
- import ODataStore from "devextreme/data/odata_store";
- // ...
- export class AppComponent {
- store: ODataStore;
- constructor() {
- this.store = new ODataStore({
- // ODataStore is configured here
- });
- this.store.insert({ id: 1, name: "John Doe" })
- .then(
- (dataObj) => { /* Process the data object here */ },
- (error) => { /* Handle the "error" here */ }
- );
- };
- }
key()
Gets the key property (or properties) as specified in the key property.
The key property's value.
- import ODataStore from "devextreme/data/odata_store";
- // ...
- export class AppComponent {
- store: ODataStore;
- constructor() {
- this.store = new ODataStore({
- // ...
- key: "ProductID"
- });
- let keyProps = this.store.key(); // returns "ProductID"
- };
- }
keyOf(obj)
Gets a data item's key value.
A data item.
The data item's key value.
- import ODataStore from "devextreme/data/odata_store";
- // ...
- export class AppComponent {
- store: ODataStore;
- constructor() {
- this.store = new ODataStore({
- // ...
- key: "id"
- });
- let key = this.store.keyOf({ id: 1, name: "John Doe" }); // returns 1
- };
- }
load()
Starts loading data.
A Promise that is resolved after data is loaded. It is a native Promise or a jQuery.Promise when you use jQuery.
load(options)
Starts loading data.
Data processing settings.
A Promise that is resolved after data is loaded. It is a native Promise or a jQuery.Promise when you use jQuery.
- import ODataStore from "devextreme/data/odata_store";
- import DevExpress from "devextreme/bundles/dx.all";
- // ...
- export class AppComponent {
- store: ODataStore;
- constructor() {
- this.store = new ODataStore({
- // ODataStore is configured here
- });
- let options: DevExpress.data.LoadOptions = {
- // Data processing settings are specified here
- };
- this.store.load(options)
- .then(
- (data) => { /* Process "data" here */ },
- (error) => { /* Handle the "error" here */ }
- );
- };
- }
off(eventName)
Detaches all event handlers from a single event.
The event's name.
The object for which this method is called.
off(eventName, eventHandler)
Detaches a particular event handler from a single event.
The object for which this method is called.
on(eventName, eventHandler)
Subscribes to an event.
The object for which this method is called.
on(events)
Subscribes to events.
Events with their handlers: { "eventName1": handler1, "eventName2": handler2, ...}
The object for which this method is called.
push(changes)
Pushes data changes to the store and notifies the DataSource.
Array<any>
Data changes to be pushed.
Each data change is an object that can have the following fields:
type: String
Data change type: "insert", "update", or "remove".data: Object
Changes that should be applied to the store's data.key: any
The key of the data item being updated or removed.index: Number
The position at which to display a new data item in a UI component bound to the store. To display the new data item first, set theindexto 0. To add it to the end of the current page, set theindexto -1.The
indexfield is optional. If you do not specify it, the new data item is added to the end of the dataset. However, if data is grouped or split into pages, this item does not appear in the UI component until data is reshaped. In this case, specify theindexto show the pushed item immediately.The
indexfield is ignored if reshapeOnPush is enabled (see the note below).
The following code shows how to use the push(changes) method for each change type:
- import ODataStore from "devextreme/data/odata_store";
- // ...
- export class AppComponent {
- store: ODataStore;
- constructor() {
- this.store = new ODataStore({
- // ODataStore is configured here
- });
- this.store.push([{ type: "insert", data: dataObj, index: index }]);
- this.store.push([{ type: "update", data: dataObj, key: key }]);
- this.store.push([{ type: "remove", key: key }]);
- };
- }
DataGrid Real-Time Updates Demo DataGrid SignalR Demo Chart SignalR Demo DataGrid Collaborative Editing Demo
See Also
- Integration with Push Services
- API Reference.WidgetName.repaintChangesOnly, for example, API Reference.DataGrid.repaintChangesOnly
remove(key)
Removes a data item with a specific key from the store.
A Promise that is resolved after the data item is removed. It is a native Promise or a jQuery.Promise when you use jQuery.
- import ODataStore from "devextreme/data/odata_store";
- // ...
- export class AppComponent {
- singleKeyStore: ODataStore;
- compositeKeyStore: ODataStore;
- constructor() {
- // The key consists of a single data field
- this.singleKeyStore = new ODataStore({
- key: "field1",
- // ...
- });
- // Removes the data item with "field1" being equal to 1
- this.singleKeyStore.remove(1)
- .then(
- (key) => { /* Process the "key" here */ },
- (error) => { /* Handle the "error" here */ }
- );
- // The key consists of several data fields
- this.compositeKeyStore = new ODataStore({
- key: [ "field1", "field2" ],
- // ...
- });
- // Removes the data item with both "field1" and "field2" being equal to 1
- this.compositeKeyStore.remove({
- field1: 1,
- field2: 1
- }).then(
- (key) => { /* Process the "key" here */ },
- (error) => { /* Handle the "error" here */ }
- );
- };
- }
totalCount(options)
Gets the total count of items the load() function returns.
A Promise that is resolved after the total item count is obtained. It is a native Promise or a jQuery.Promise when you use jQuery.
- import ODataStore from "devextreme/data/odata_store";
- // ...
- export class AppComponent {
- store: ODataStore;
- constructor() {
- this.store = new ODataStore({
- // ODataStore is configured here
- });
- this.store.totalCount()
- .then(
- (count) => { /* Process the "count" here */ },
- (error) => { /* Handle the "error" here */ }
- );
- };
- }
update(key, values)
Updates a data item with a specific key.
A Promise that is resolved after the data item is updated. It is a native Promise or a jQuery.Promise when you use jQuery.
In the following code, dataObj is a data object updated in the database and returned from the server. If the server returns nothing or the store works with local data, dataObj contains the data object passed to the update method.
- import ODataStore from "devextreme/data/odata_store";
- // ...
- export class AppComponent {
- singleKeyStore: ODataStore;
- compositeKeyStore: ODataStore;
- constructor() {
- // The key consists of a single data field
- this.singleKeyStore = new ODataStore({
- key: "field1",
- // ...
- });
- // Updates the data item with "field1" being equal to 1
- this.singleKeyStore.update(1, { name: "John Smith" })
- .then(
- (dataObj) => { /* Process the data object here */ },
- (error) => { /* Handle the "error" here */ }
- );
- // The key consists of several data fields
- this.compositeKeyStore = new ODataStore({
- key: [ "field1", "field2" ],
- // ...
- });
- // Updates the data item with both "field1" and "field2" being equal to 1
- this.compositeKeyStore.update(
- { field1: 1, field2: 1 },
- { name: "John Smith" }
- ).then(
- (dataObj) => { /* Process the data object here */ },
- (error) => { /* Handle the "error" here */ }
- );
- };
- }