Your search did not match any results.
Data Grid

Toolbar Customization

Documentation
The DataGrid widget allows you to customize its toolbar using the onToolbarPreparing function. You can add new items to the toolbar or customize the existing ones. In this demo, the toolbar contains a collection of other widgets from the DevExtreme HTML5 UI Widgets library.
Apply
Reset
<dx-data-grid id="gridContainer" [dataSource]="orders" (onToolbarPreparing)="onToolbarPreparing($event)"> <dxo-grouping [autoExpandAll]="expanded"></dxo-grouping> <dxo-column-chooser [enabled]="true"></dxo-column-chooser> <dxo-load-panel [enabled]="true"></dxo-load-panel> <dxi-column dataField="OrderNumber"></dxi-column> <dxi-column dataField="OrderDate"></dxi-column> <dxi-column dataField="Employee"></dxi-column> <dxi-column dataField="CustomerStoreCity" caption="City"></dxi-column> <dxi-column dataField="CustomerStoreState" caption="State" [groupIndex]="0"></dxi-column> <dxi-column dataField="SaleAmount" alignment="right" format="currency"></dxi-column> <div *dxTemplate="let data of 'totalGroupCount'"> <div class="informer"> <h2 class="count">{{totalCount}}</h2> <span class="name">Total Count</span> </div> </div> </dx-data-grid>
import { NgModule, Component, ViewChild } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { DxDataGridModule, DxDataGridComponent, DxTemplateModule } from 'devextreme-angular'; import { Service, Order } from './app.service'; import query from 'devextreme/data/query'; @Component({ selector: 'demo-app', templateUrl: 'app/app.component.html', styleUrls: ['app/app.component.css'], providers: [Service] }) export class AppComponent { @ViewChild(DxDataGridComponent) dataGrid: DxDataGridComponent; orders: Order[]; expanded = true; totalCount: number; constructor(service: Service) { this.orders = service.getOrders(); this.totalCount = this.getGroupCount('CustomerStoreState'); } getGroupCount(groupField) { return query(this.orders) .groupBy(groupField) .toArray().length; } onToolbarPreparing(e) { e.toolbarOptions.items.unshift({ location: 'before', template: 'totalGroupCount' }, { location: 'before', widget: 'dxSelectBox', options: { width: 200, items: [{ value: 'CustomerStoreState', text: 'Grouping by State' }, { value: 'Employee', text: 'Grouping by Employee' }], displayExpr: 'text', valueExpr: 'value', value: 'CustomerStoreState', onValueChanged: this.groupChanged.bind(this) } }, { location: 'before', widget: 'dxButton', options: { hint: 'Collapse All', icon: 'chevrondown', onClick: this.collapseAllClick.bind(this) } }, { location: 'after', widget: 'dxButton', options: { icon: 'refresh', onClick: this.refreshDataGrid.bind(this) } }); } groupChanged(e) { this.dataGrid.instance.clearGrouping(); this.dataGrid.instance.columnOption(e.value, 'groupIndex', 0); this.totalCount = this.getGroupCount(e.value); } collapseAllClick(e) { this.expanded = !this.expanded; e.component.option({ icon: this.expanded ? 'chevrondown' : 'chevronnext', hint: this.expanded ? 'Collapse All' : 'Expand All' }); } refreshDataGrid() { this.dataGrid.instance.refresh(); } } @NgModule({ imports: [ BrowserModule, DxDataGridModule, DxTemplateModule ], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } platformBrowserDynamic().bootstrapModule(AppModule);
/deep/ .dx-datagrid-header-panel .dx-toolbar { margin: 0; padding-right: 20px; background-color: #5186C3; } /deep/ .dx-datagrid-header-panel .dx-toolbar-items-container { height: 70px; } /deep/ .dx-datagrid-header-panel .dx-toolbar-before { background-color: #337AB7; } /deep/ .dx-datagrid-header-panel .dx-selectbox { margin: 17px 10px; } /deep/ .dx-datagrid-header-panel .dx-button { margin: 17px 0; } /deep/ .informer { height: 70px; width: 130px; text-align: center; background: #2A507C url("../../../../images/icons/arrow.png") no-repeat 100% 50%; } /deep/ .count { color: #fff; padding-top: 15px; line-height: 27px; } /deep/ .name { color: #619dd1; }
import { Injectable } from '@angular/core'; export class Order { ID: number; OrderNumber: number; OrderDate: string; SaleAmount: number; Terms: string; CustomerStoreState: string; CustomerStoreCity: string; Employee:string; } let orders: Order[] = [{ "ID": 1, "OrderNumber": 35703, "OrderDate": "2014/02/13", "SaleAmount": 11800, "Terms": "15 Days", "CustomerStoreState": "California", "CustomerStoreCity": "Los Angeles", "Employee": "Harv Mudd" }, { "ID": 4, "OrderNumber": 35711, "OrderDate": "2014/03/21", "SaleAmount": 16050, "Terms": "15 Days", "CustomerStoreState": "California", "CustomerStoreCity": "San Jose", "Employee": "Jim Packard" }, { "ID": 5, "OrderNumber": 35714, "OrderDate": "2014/04/19", "SaleAmount": 14750, "Terms": "15 Days", "CustomerStoreState": "Nevada", "CustomerStoreCity": "Las Vegas", "Employee": "Harv Mudd" }, { "ID": 7, "OrderNumber": 35983, "OrderDate": "2014/01/12", "SaleAmount": 3725, "Terms": "15 Days", "CustomerStoreState": "Colorado", "CustomerStoreCity": "Denver", "Employee": "Todd Hoffman" }, { "ID": 9, "OrderNumber": 36987, "OrderDate": "2014/04/08", "SaleAmount": 14200, "Terms": "15 Days", "CustomerStoreState": "Utah", "CustomerStoreCity": "Salt Lake City", "Employee": "Clark Morgan" }, { "ID": 11, "OrderNumber": 38466, "OrderDate": "2014/02/28", "SaleAmount": 7800, "Terms": "15 Days", "CustomerStoreState": "California", "CustomerStoreCity": "Los Angeles", "Employee": "Harv Mudd" }, { "ID": 15, "OrderNumber": 39874, "OrderDate": "2014/05/28", "SaleAmount": 9050, "Terms": "30 Days", "CustomerStoreState": "Nevada", "CustomerStoreCity": "Las Vegas", "Employee": "Harv Mudd" }, { "ID": 18, "OrderNumber": 42847, "OrderDate": "2014/02/06", "SaleAmount": 20400, "Terms": "30 Days", "CustomerStoreState": "Wyoming", "CustomerStoreCity": "Casper", "Employee": "Todd Hoffman" }, { "ID": 19, "OrderNumber": 43982, "OrderDate": "2014/02/16", "SaleAmount": 6050, "Terms": "30 Days", "CustomerStoreState": "Utah", "CustomerStoreCity": "Salt Lake City", "Employee": "Clark Morgan" }, { "ID": 29, "OrderNumber": 56272, "OrderDate": "2014/01/25", "SaleAmount": 15850, "Terms": "30 Days", "CustomerStoreState": "Utah", "CustomerStoreCity": "Salt Lake City", "Employee": "Clark Morgan" }, { "ID": 30, "OrderNumber": 57429, "OrderDate": "2013/12/31", "SaleAmount": 11050, "Terms": "30 Days", "CustomerStoreState": "Arizona", "CustomerStoreCity": "Phoenix", "Employee": "Clark Morgan" }, { "ID": 32, "OrderNumber": 58292, "OrderDate": "2014/04/29", "SaleAmount": 13500, "Terms": "15 Days", "CustomerStoreState": "California", "CustomerStoreCity": "Los Angeles", "Employee": "Harv Mudd" }]; @Injectable() export class Service { getOrders(): Order[] { return orders; } }
// In real applications, you should not transpile code in the browser. You can see how to create your own application with Angular 2 and DevExtreme here: // https://github.com/DevExpress/devextreme-angular/blob/master/README.md System.config({ transpiler: 'ts', typescriptOptions: { module: "commonjs", emitDecoratorMetadata: true, experimentalDecorators: true }, meta: { 'typescript': { "exports": "ts" } }, paths: { 'npm:': 'https://unpkg.com/' }, map: { 'ts': 'npm:plugin-typescript@4.0.10/lib/plugin.js', 'typescript': 'npm:typescript@2.0.6/lib/typescript.js', '@angular/core': 'npm:@angular/core@2.4.3/bundles/core.umd.js', '@angular/common': 'npm:@angular/common@2.4.3/bundles/common.umd.js', '@angular/compiler': 'npm:@angular/compiler@2.4.3/bundles/compiler.umd.js', '@angular/platform-browser': 'npm:@angular/platform-browser@2.4.3/bundles/platform-browser.umd.js', '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic@2.4.3/bundles/platform-browser-dynamic.umd.js', '@angular/http': 'npm:@angular/http@2.4.3/bundles/http.umd.js', '@angular/router': 'npm:@angular/router@3.4.3/bundles/router.umd.js', '@angular/forms': 'npm:@angular/forms@2.4.3/bundles/forms.umd.js', 'rxjs': 'npm:rxjs@5.0.3', 'devextreme': 'npm:devextreme@16.2', 'jquery': 'npm:jquery@3.1.1/dist/jquery.min.js', 'jszip': 'npm:jszip@3.1.3/dist/jszip.min.js', 'devextreme-angular': 'npm:devextreme-angular@16.2' }, packages: { 'app': { main: './app.component.ts', defaultExtension: 'ts' }, 'devextreme': { defaultExtension: 'js' }, 'devextreme-angular': { main: 'index.js', defaultExtension: 'js' } } });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <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="https://cdn3.devexpress.com/jslib/16.2.5/css/dx.spa.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/16.2.5/css/dx.common.css" /> <link rel="dx-theme" data-theme="generic.light" href="https://cdn3.devexpress.com/jslib/16.2.5/css/dx.light.css" /> <script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script> <script src="https://unpkg.com/zone.js@0.6.25/dist/zone.js"></script> <script src="https://unpkg.com/reflect-metadata@0.1.3/Reflect.js"></script> <script src="https://unpkg.com/systemjs@0.19.31/dist/system.js"></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>