Your search did not match any results.
Data Grid

Custom Data Source


For consuming data from a data source, which is not supported by the DevExtreme data layer out of the box, the DataGrid uses the CustomStore. To load data, the CustomStore needs the load function that you should implement by yourself. Note that this store can be declared explicitly or in the DataSource configuration object.

Copy to CodeSandBox
<dx-data-grid id="gridContainer" [dataSource]="dataSource" [showBorders]="true" [remoteOperations]="true"> <dxi-column dataField="OrderNumber" dataType="number"> </dxi-column> <dxi-column dataField="OrderDate" dataType="date"> </dxi-column> <dxi-column dataField="StoreCity" dataType="string"> </dxi-column> <dxi-column dataField="StoreState" dataType="string"> </dxi-column> <dxi-column dataField="Employee" dataType="string"> </dxi-column> <dxi-column dataField="SaleAmount" dataType="number" format="currency"> </dxi-column> <dxo-paging [pageSize]="12"></dxo-paging> <dxo-pager [showPageSizeSelector]="true" [allowedPageSizes]="[8, 12, 20]" ></dxo-pager> </dx-data-grid>
import { NgModule, Component, enableProdMode } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { HttpClient, HttpClientModule, HttpParams } from '@angular/common/http'; import { DxDataGridModule } from 'devextreme-angular'; import CustomStore from 'devextreme/data/custom_store'; if(!/localhost/.test( { enableProdMode(); } @Component({ styleUrls: ['app/app.component.css'], selector: 'demo-app', templateUrl: 'app/app.component.html' }) export class AppComponent { dataSource: any = {}; constructor(httpClient: HttpClient) { function isNotEmpty(value: any): boolean { return value !== undefined && value !== null && value !== ""; } this.dataSource = new CustomStore({ key: "OrderNumber", load: function (loadOptions: any) { let params: HttpParams = new HttpParams(); [ "skip", "take", "requireTotalCount", "requireGroupCount", "sort", "filter", "totalSummary", "group", "groupSummary" ].forEach(function(i) { if (i in loadOptions && isNotEmpty(loadOptions[i])) params = params.set(i, JSON.stringify(loadOptions[i])); }); return httpClient.get('', { params: params }) .toPromise() .then((data: any) => { return { data:, totalCount: data.totalCount, summary: data.summary, groupCount: data.groupCount }; }) .catch(error => { throw 'Data Loading Error' }); } }); } } @NgModule({ imports: [ BrowserModule, DxDataGridModule, HttpClientModule ], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } platformBrowserDynamic().bootstrapModule(AppModule);
// In real applications, you should not transpile code in the browser. You can see how to create your own application with Angular and DevExtreme here: // System.config({ transpiler: 'ts', typescriptOptions: { module: "system", emitDecoratorMetadata: true, experimentalDecorators: true }, meta: { 'typescript': { "exports": "ts" }, }, paths: { 'npm:': '' }, map: { 'ts': 'npm:plugin-typescript@8.0.0/lib/plugin.js', 'typescript': 'npm:typescript@3.4.5/lib/typescript.js', '@angular': 'npm:@angular', 'tslib': 'npm:tslib/tslib.js', 'rxjs': 'npm:rxjs', 'devextreme': 'npm:devextreme@20.1', 'jszip': 'npm:jszip@3.1.3/dist/jszip.min.js', 'quill': 'npm:quill@1.3.7/dist/quill.js', 'devexpress-diagram': 'npm:devexpress-diagram@1.0.5', 'devexpress-gantt': 'npm:devexpress-gantt@1.0.3', 'devextreme-angular': 'npm:devextreme-angular@20.1' }, packages: { 'app': { main: './app.component.ts', defaultExtension: 'ts' }, 'devextreme': { defaultExtension: 'js' }, 'devextreme/events/utils': { main: 'index' }, 'devextreme/events': { main: 'index' }, }, packageConfigPaths: [ "npm:*/package.json", "npm:@angular/*/package.json", "npm:@angular/common/*/package.json", "npm:rxjs/operators/package.json", "npm:devextreme-angular@20.1/*/package.json", "npm:devextreme-angular@20.1/ui/*/package.json", ] });
<!DOCTYPE html> <html xmlns=""> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <link rel="stylesheet" type="text/css" href="" /> <link rel="stylesheet" type="text/css" href="" /> <script src=""></script> <script src=""></script> <script src=""></script> <script src=""></script> <script src="config.js"></script> <script> System.import('app').catch(console.error.bind(console)); </script> </head> <body class="dx-viewport"> <div class="demo-container"> <demo-app>Loading...</demo-app> </div> </body> </html>