--- name: devextreme-datasource description: > Help developers configure the DevExtreme data layer across Angular, React, Vue, jQuery, and ASP.NET Core Controls: DataSource, ArrayStore, LocalStore, ODataStore, and CustomStore. Use when someone asks about binding components to data, loading data from a REST API, configuring an OData endpoint, implementing a custom data source, client-side vs server-side data processing, paging, sorting, filtering, or editing through a store. Trigger phrases: "DataSource", "ArrayStore", "ODataStore", "CustomStore", "LocalStore", "custom store", "load function", "byKey", "loadMode", "remoteOperations", "data binding", "server-side paging", "REST API data", "data layer". compatibility: DevExtreme 26.1+. Framework-agnostic (TypeScript/JavaScript); UI snippets shown for Angular, React, Vue, jQuery, and ASP.NET Core Controls. metadata: author: DevExpress version: "26.1" --- # DevExtreme Data Layer Skill A skill for configuring the DevExtreme data layer: `DataSource`, `ArrayStore`, `LocalStore`, `ODataStore`, and `CustomStore`. ## When to Use This Skill - Binding a component (`dataSource` property) to a plain array, a URL, or a Store - Configuring paging, sorting, filtering, and grouping at the DataSource level - Connecting to an OData endpoint - Implementing a `CustomStore` to load data from any REST API - Implementing `insert`, `update`, `remove` in a `CustomStore` for editable components (DataGrid, etc.) - Deciding between client-side and server-side data processing modes ## Before You Start If the host agent has a structured question-asking tool available, use it to ask these questions one at a time with clear options — for example, Claude Code's `AskUserQuestion` tool or GitHub Copilot's `askQuestions` tool. If no such tool is available, ask the questions directly in the chat response before generating code. > ⚠️ **Always use DevExtreme's `CustomStore`, `DataSource`, or a built-in Store (`ArrayStore`, `ODataStore`) for data binding. Never replace them with raw `fetch`/`axios`, react-query, SWR, or any other data-fetching library. For user-visible error notifications, always use `notify` from `devextreme/ui/notify`.** 1. **Which framework?** Angular, React, Vue, jQuery, or ASP.NET Core Controls? 2. **Which component is this data source for?** Determines whether `loadMode: 'raw'` applies and which `...Expr` field mappings are relevant. 3. **Local, OData, or custom REST?** Local array → `ArrayStore`. OData service → `ODataStore`. Anything else → `CustomStore`. Skip the framework question if the request or project already identifies the framework. If the reply leaves it unresolved, re-ask once with the list: Angular, React, Vue, jQuery, or ASP.NET Core Controls. If it remains unresolved, default to React + Vite + TypeScript and state that assumption. ## Architecture Overview ```text UI Component └── DataSource — orchestrates paging, sorting, grouping, filtering └── Store — handles raw data access (CRUD) ├── ArrayStore — in-memory array ├── LocalStore — HTML5 localStorage ├── ODataStore — OData v2/v3/v4 endpoint └── CustomStore — any backend (REST, GraphQL, etc.) ``` A component's `dataSource` property accepts: - A **plain array** — DevExtreme wraps it in an `ArrayStore` + `DataSource` automatically. - A **URL string** — DevExtreme fetches JSON and wraps it in a `DataSource`. - A **Store instance** — passed directly or wrapped in a `DataSource`. - A **DataSource instance** — gives full control over paging, sorting, grouping. - A **DataSource config object** — DevExtreme constructs the `DataSource` for you. ## Documentation Reference Files | File | When you need to | |---|---| | [references/stores.md](references/stores.md) | Use ArrayStore, LocalStore, or ODataStore | | [references/custom-store.md](references/custom-store.md) | Implement CustomStore for any REST/custom backend | | [references/datasource-options.md](references/datasource-options.md) | Configure DataSource-level options: paging, sort, filter, group, map, postProcess | ## Key API Summary ### DataSource options (most used) | Option | Type | Description | |---|---|---| | `store` | `Store \| StoreConfig` | The underlying store | | `filter` | `Filter` | Static client-side filter applied on load | | `sort` | `Sort` | Default sort order | | `group` | `Group` | Default grouping | | `paginate` | `Boolean` | Enables paging (default `true` for most components) | | `pageSize` | `Number` | Items per page (default `20`) | | `requireTotalCount` | `Boolean` | Requests total item count alongside data | | `reshapeOnPush` | `Boolean` | Triggers UI re-render on `push()` calls | | `searchExpr` | `String \| Array` | Fields to search against | | `searchValue` | `any` | Search value | | `select` | `Array` | Field projection | | `map` | `function(item)` | Transforms each item after load | | `postProcess` | `function(data)` | Transforms the full loaded dataset | ### Store base options (all stores) | Option | Description | |---|---| | `key` | Primary key field name(s) | | `onLoaded` | Fires after data is loaded | | `onInserting` / `onInserted` | Fires before/after insert | | `onUpdating` / `onUpdated` | Fires before/after update | | `onRemoving` / `onRemoved` | Fires before/after remove | | `errorHandler` | Global error handler for store operations | ## Quick-Start Patterns ### Plain array (simplest) ```ts // Any framework — just pass the array dataSource = [ { id: 1, name: 'Alice' }, { id: 2, name: 'Bob' } ]; // In template / options: dataSource={dataSource} or [dataSource]="dataSource" ``` ### ArrayStore with a DataSource ```ts import ArrayStore from 'devextreme/data/array_store'; import DataSource from 'devextreme/data/data_source'; const store = new ArrayStore({ key: 'id', data: [ { id: 1, name: 'Alice' }, { id: 2, name: 'Bob' } ] }); const dataSource = new DataSource({ store, sort: 'name', pageSize: 10 }); ``` ### ODataStore ```ts import ODataStore from 'devextreme/data/odata/store'; const dataSource = new ODataStore({ url: 'https://services.odata.org/V4/Northwind/Northwind.svc/Products', key: 'ProductID', version: 4 }); ``` ### CustomStore (client-side mode — load all data at once) ```ts import CustomStore from 'devextreme/data/custom_store'; const store = new CustomStore({ key: 'ID', loadMode: 'raw', // DevExtreme handles paging/sorting/filtering client-side load() { return fetch('https://api.example.com/items').then(r => r.json()); } }); ``` ### CustomStore (server-side mode — component passes loadOptions) See [references/custom-store.md](references/custom-store.md) for the full server-side pattern. ## ASP.NET Core Controls In ASP.NET Core, configure data access through the MVC data source builder. ```cshtml @(Html.DevExtreme().DataGrid() .ID("ordersGrid") .DataSource(d => d.Mvc() .Controller("Orders") .LoadAction("Get") .InsertAction("Post") .UpdateAction("Put") .DeleteAction("Delete") .Key("OrderID") ) ) ``` ### Binding to an API on a different site `.Mvc()` and `.WebApi()` both assume the controller lives in the **current** ASP.NET Core app — they generate relative action URLs. When the API is on a different origin (a separate service, a public demo API, a different port), use `.RemoteController()` instead, with fully-qualified URLs: ```cshtml @(Html.DevExtreme().DataGrid() .ID("ordersGrid") .DataSource(ds => ds.RemoteController() .Key("OrderID") .LoadUrl("https://api.example.com/Orders/Get") .InsertUrl("https://api.example.com/Orders/Insert") .UpdateUrl("https://api.example.com/Orders/Update") .DeleteUrl("https://api.example.com/Orders/Delete") ) ) ``` > **`.WebApi().Controller(...)` with a full URL in `LoadAction`/`InsertAction`/etc. does not work** for a remote origin — those actions build relative routes against the current app, so a full URL there produces a wrong local route (404s), not a cross-origin request. If the load/insert/update/delete endpoints are absolute URLs to another site, reach for `.RemoteController()` with `.LoadUrl()`/`.InsertUrl()`/`.UpdateUrl()`/`.DeleteUrl()`, not `.WebApi()` with `.LoadAction()`/etc. ## Framework Rules Apply the conventions for the framework selected by the developer. ### Angular - Use standalone components and import the component-specific standalone DevExtreme exports unless the developer explicitly uses NgModules. - When supporting an older DevExtreme release without standalone exports, use that release's documented NgModule integration. - For nested configuration, use the most specific component export available (for example, a component-specific pager or item) instead of assuming a generic `Dxo*` or `Dxi*` export. - Prefer the component's aggregated event/types export, such as `DxDateBoxTypes`, when the package exposes one. ### React - Use function components and hooks. Generate TypeScript unless the developer requests JavaScript, and avoid `any` when a concrete DevExtreme type exists. - Prefer the component's aggregated types export, such as `DateBoxTypes`. - For a new React application, reuse the developer's tool or framework choice; ask only if it is unresolved. Recommend Vite when they have no preference; do not scaffold deprecated Create React App unless explicitly requested. ### Vue - Use Vue 3 with the Composition API and `