DevExtreme React - CustomStore Props
byKey
Specifies a custom implementation of the byKey(key) method.
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 CustomStore from 'devextreme/data/custom_store';
- import DataSource from 'devextreme/data/data_source';
- import 'whatwg-fetch';
- const store = new CustomStore({
- // ...
- byKey: (key) => {
- return fetch("http://mydomain.com/MyDataService?id=" + key);
- }
- });
- class App extends React.Component {
- // ...
- }
- export default App;
cacheRawData
Specifies whether raw data should be saved in the cache. Applies only if loadMode is "raw".
Data caching allows the CustomStore to decrease the number of data requests. On the downside, cached data and data in your source may become out of sync. If keeping them synchronized is crucial in your scenario, disable data caching by setting the cacheRawData property to false. In this case, the CustomStore will send a request for data on every call of the load, byKey and totalCount functions.
See Also
errorHandler
This function accepts a JavaScript Error object as the parameter.
- // ...
- import CustomStore from 'devextreme/data/custom_store';
- const store = new CustomStore({
- // ...
- errorHandler: (error) => {
- console.log(error.message);
- }
- });
- class App extends React.Component {
- // ...
- }
- export default App;
insert
Specifies a custom implementation of the insert(values) method.
A Promise that is resolved after the data item is inserted. It is a native Promise or a jQuery.Promise when you use jQuery.
- // ...
- import CustomStore from 'devextreme/data/custom_store';
- import DataSource from 'devextreme/data/data_source';
- import 'whatwg-fetch';
- function handleErrors(response) {
- if (!response.ok)
- throw Error(response.statusText);
- return response;
- }
- const store = new CustomStore({
- // ...
- insert: (values) => {
- return fetch("https://mydomain.com/MyDataService/myEntity", {
- method: "POST",
- body: JSON.stringify(values),
- headers: {
- 'Content-Type': 'application/json'
- }
- })
- .then(handleErrors);
- }
- });
- class App extends React.Component {
- // ...
- }
- export default App;
key
Specifies the key property (or properties) that provide(s) key values to access data items. Each key value must be unique.
In the following example, the ProductID
and ProductCode
properties are specified as key properties:
- // ...
- import CustomStore from 'devextreme/data/custom_store';
- const store = new CustomStore({
- // ...
- key: ['ProductID', 'ProductCode']
- });
- class App extends React.Component {
- // ...
- }
- export default App;
load
Specifies a custom implementation of the load(options) method.
An array with data or a Promise that is resolved after data is loaded. It is a native Promise or a jQuery.Promise when you use jQuery.
Refer to the following help topic for information on how to implement the load function: Custom Data Sources.
See Also
loadMode
Specifies how data returned by the load function is treated.
Specify this property depending on the behavior you implemented for the load function. If this function sends data shaping properties to the server and fetches processed data, then loadMode should be set to "processed". If the load function simply fetches raw, unprocessed data from the server, set loadMode to "raw". In this case, the raw data will be processed on the client automatically.
See Also
remove
Specifies a custom implementation of the remove(key) method.
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 CustomStore from 'devextreme/data/custom_store';
- import DataSource from 'devextreme/data/data_source';
- import 'whatwg-fetch';
- function handleErrors(response) {
- if (!response.ok)
- throw Error(response.statusText);
- return response;
- }
- const store = new CustomStore({
- // ...
- remove: (key) => {
- return fetch(`https://mydomain.com/MyDataService/${encodeURIComponent(key)}`, {
- method: "DELETE"
- })
- .then(handleErrors);
- });
- });
- class App extends React.Component {
- // ...
- }
- export default App;
totalCount
Specifies a custom implementation of the totalCount(options) method.
A Promise that is resolved after data is loaded. It is a native Promise or a jQuery.Promise when you use jQuery.
update
Specifies a custom implementation of the update(key, values) method.
A Promise that is resolved after the data item is updated. It is a native Promise or a jQuery.Promise when you use jQuery.
- // ...
- import CustomStore from 'devextreme/data/custom_store';
- import DataSource from 'devextreme/data/data_source';
- import 'whatwg-fetch';
- function handleErrors(response) {
- if (!response.ok)
- throw Error(response.statusText);
- return response;
- }
- const store = new CustomStore({
- // ...
- update: (key, values) => {
- return fetch(`https://mydomain.com/MyDataService/${encodeURIComponent(key)}`, {
- method: "PUT",
- body: JSON.stringify(values),
- headers: {
- 'Content-Type': 'application/json'
- }
- })
- .then(handleErrors);
- }
- });
- class App extends React.Component {
- // ...
- }
- export default App;
useDefaultSearch
Specifies whether the store combines the search and filter expressions. Defaults to true if the loadMode is "raw" and false if it is "processed".
If you have technical questions, please create a support ticket in the DevExpress Support Center.