23.2.5 • Published 9 days ago

devextreme-angular v23.2.5

Weekly downloads
84,904
License
MIT
Repository
github
Last release
9 days ago

Run Status npm version

If you are looking for the 17.2 branch, please forward the following link.

Angular UI and Visualization Components Based on DevExtreme Widgets

This project allows you to use DevExtreme Widgets in Angular applications.

Getting Started

You have the following options to start:

Prerequisites

Node.js and npm are required and essential to Angular development.

Gulp is required to build the project and run tests.

Adding DevExteme to an Existing Angular Application

Install DevExtreme

Install the devextreme and devextreme-angular npm packages:

npm install --save devextreme devextreme-angular

Additional Configuration

The further configuration steps depend on which build tool, bundler or module loader you are using. Please choose the one you need:

Import DevExtreme Modules

Go to your main .ts file (usually src/app.module.ts) and import the required modules to your app:

...
import { DxButtonModule } from 'devextreme-angular';

@NgModule({
    ...
    imports: [
        ...
        DxButtonModule,
        ...
    ]
})
export class AppModule {}

Note, you can import the DevExtremeModule module to include all the DevExtreme components at once, but it might affect the final bundle size and startup time. Check the bundle optimization section for more info.

Use DevExtreme Components

Now you can use a DevExteme component in your application:

@Component({
    selector: 'my-app',
    template: '<dx-button text="Press me" (onClick)="helloWorld()"></dx-button>'
})
export class AppComponent {
    helloWorld() {
        alert('Hello world!');
    }
}

Create a new Angular Application

Depending on your requirements you can choose one of the following ways to start:

Running the Local Examples

# clone our repo
# --depth 1 removes all but one .git commit history
git clone --depth 1 https://github.com/DevExpress/devextreme-angular.git

# change directory to our repo
cd devextreme-angular

# install the repo with npm
npm install

# start the web-server
npm start

Navigate to http://127.0.0.1:8875/examples/ in the opened browser window. Explore the examples folder of this repository for the examples source code.

Include jQuery integration

Starting with version 17.2, DevExtreme doesn't depend on jQuery. It means that our widgets work without jQuery elements. If you need to use jQuery, you can manually install the jquery npm package and include the jQuery integration as described below:

npm install --save jquery
import 'devextreme/integration/jquery';

Usage Samples

Static String Option Value

To specify a string widget's option statically (the text option of dxButton):

<dx-button text="Simple button"></dx-button>

Static Non-string Option Value

To specify a non-string widget's option statically (the disabled option of dxButton):

<dx-button [disabled]="false"></dx-button>

Event Handling

To bind the dxButton’s click event:

<dx-button (onClick)="handler()"></dx-button>

Callback Functions

To specify a widget's option using a callback function (the layer.customize option of dxVectorMap):

<dx-vector-map>
    ...
    <dxi-layer
        ...
        [customize]="customizeLayers">
    </dxi-layer>
</dx-vector-map>

Note that callback functions are executed outside the context of the component, but if the context is important, you can explicitly bind it to the callback function in the constructor.

constructor() {
    this.customizeLayers = this.customizeLayers.bind(this);
}

customizeLayers(elements) {
    let country = this.myCountry;
    ...
}

One-way Option Binding

If we want changes to the value of ‘bindingProperty’ of the host component to propagate to the value of the dxTextBox widget, a one-way binding approach is used:

<dx-text-box [value]="bindingProperty"></dx-text-box>

Two-way Option Binding

In addition to the one-way binding, we can also perform two-way binding, which propagates changes from the bindingProperty to the widget or vice versa from the widget to the bindingProperty:

<dx-text-box [(value)]="bindingProperty"></dx-text-box>

Custom Templates

In case you want to customize the rendering of a DevExtreme widget, we support custom templates. For instance, we can specify the itemTemplate and groupTemplate of the dxList widget as follows:

<dx-list [grouped]="true" [items]="grouppedItems">
    <div *dxTemplate="let itemData of 'item'; let itemIndex = index">
        {{itemIndex}} - {{itemData.someProperty}}
    </div>
    <div *dxTemplate="let groupData of 'group'">
        {{groupData.someProperty}}
    </div>
</dx-list>

The local 'itemData' and 'groupData' variables (that are declared via the 'let' keyword) expose the corresponding item data object. You can use it to render the data where you need inside the template.

The 'item' and 'group' names are default template names for the 'itemTemplate' and 'groupTemplate' options of the dxList widget.

Data Layer

The DevExtreme framework includes a data layer, which is a set of complementary components that enable you to read and write data. For more details please refer to the documentation on the official website.

DevExtreme Utils

The DevExtreme provides utils that can be used in different application parts such as widgets and data. For more details please refer to the documentation on the official website.

Components with Transcluded Content

In addition to using dxTemplate, it is possible to put the content of the following widgets directly into the markup: dxResizable, dxScrollView, dxValidationGroup. For instance, we can set the content for the dxScrollView widget as shown below:

<dx-scroll-view>
    <div>Some scrollable content</div>
</dx-scroll-view>

Angular Forms

The DevExtreme Angular editors support the 'ngModel' binding as well as the 'formControlName' directive, which are necessary for the Angular forms features.

<form [formGroup]="form">
        <dx-text-box
            name="email"
            [(ngModel)]="email"
            [isValid]="emailControl.valid || emailControl.pristine"
            [validationError]="{ message: 'Email is invalid'}">
        </dx-text-box>
</form>
@Component({
   selector: 'my-app',
   templateUrl: 'app/app.component.html'
})
export class AppComponent implements OnInit {
   email: string;
   emailControl: AbstractControl;
   form: FormGroup;
   ngOnInit() {
       this.form = new FormGroup({
           email: new FormControl('', Validators.compose([Validators.required, CustomValidator.mailFormat]))
       });
       this.emailControl = this.form.controls['email'];
   }
}

Using DevExtreme Validation Features

You can use the built-in validators, validation summary and other DevExtreme validation features with Angular DevExtreme editors.

<dx-validation-group>

    <dx-text-box [(value)]="email">
        <dx-validator [validationRules]="validationRules.email"></dx-validator>
    </dx-text-box>
    <dx-text-box [(value)]="password" mode="password">
        <dx-validator [validationRules]="validationRules.password"></dx-validator>
    </dx-text-box>

    <dx-validation-summary></dx-validation-summary>

    <dx-button (onClick)="validate($event)" text="Submit"></dx-button>

</dx-validation-group>
@Component({
    selector: 'my-app',
    templateUrl: 'app/app.component.html'
})
export class AppComponent {
    email: string;
    password: string;
    validationRules = {
        email: [
            { type: 'required', message: 'Email is required.' },
            { type: 'email', message: 'Email is invalid.' }
        ],
        password: [
            { type: 'required', message: 'Email is required.' }
        ]
    };
    validate(params) {
        let result = params.validationGroup.validate();
        if (result.isValid) {
            // form data is valid
            // params.validationGroup.reset();
        }
    }
}

Configuration Components

You can use dxo- ('o' is a contraction of 'option') prefixed components to configure complex nested options for widgets. The following example demonstrates how to configure the tooltip option of the dxTreeMap widget:

<dx-tree-map [dataSource]="treeData">
    <dxo-tooltip [enabled]="showTooltip" format="thousands"></dxo-tooltip>
</dx-tree-map>

<dx-button text="Toggle tooltip" (onClick)="toggleTooltip()"></dx-button>
@Component({
    selector: 'my-app',
    templateUrl: 'app/app.component.html'
})
export class AppComponent {
    treeData = ...;
    showTooltip = false;
    toggleTooltip() {
        this.showTooltip = !this.showTooltip;
    }
}

You can also use dxi- ('i' is a contraction of 'item') prefixed components to configure complex collection options for widgets. The following example demonstrates how to configure the columns option of the dxDataGrid widget:

<dx-data-grid [dataSource]="data">
    <dxi-column dataField="firstName" caption="First Name"></dxi-column>
    <dxi-column dataField="lastName" caption="Last Name" [visible]="showLastName"></dxi-column>
</dx-data-grid>

<dx-button text="Toggle the 'Last Name' column" (onClick)="toggleLastName()"></dx-button>
@Component({
    selector: 'my-app',
    templateUrl: 'app/app.component.html'
})
export class AppComponent {
    data = ...;
    showLastName = false;
    toggleLastName() {
        this.showLastName = !this.showLastName;
    }
}

To configure options that can accept a configuration object or an array of configuration objects, use dxi- prefixed components. The following example demonstrates how to configure the valueAxis option of the dxChart widget:

<dx-chart [dataSource]="data">
    <dxi-series valueField="value" argumentField="argument"></dxi-series>
    <dxi-value-axis>
        <dxo-label format="millions"></dxo-label>
    </dxi-value-axis>
</dx-chart>
@Component({
    selector: 'my-app',
    templateUrl: 'app/app.component.html'
})
export class AppComponent {
    data = ...;
}

It is possible to specify an item template inside the dxi- prefixed components and use Angular structural directives such as ngFor. Note that the available item properties are described in the Default Item Template section of a corresponding widget documentation reference.

<dx-list>
    <dxi-item>
        <h1>Items available</h1>
    </dxi-item>
    <dxi-item *ngFor="let item of listItems" [badge]="item.badge">
        <h2>{{item.text}}</h2>
    </dxi-item>
</dx-list>
@Component({
    selector: 'my-app',
    templateUrl: 'app/app.component.html'
})
export class AppComponent {
    listItems = [
        {
            text: 'Cars',
            badge: '12'
        },
        {
            text: 'Bikes',
            badge: '5'
        }
    ];
}

If your item template contains some nested components, declare it using the parameterless dxTemplate structural directive as follows:

<dx-list>
    <dxi-item>
        <div *dxTemplate>
            <dx-button text="I'm a nested child component"></dx-button>
        </div>
    </dxi-item>
</dx-list>

Angular has a built-in template directive. To define the template property of the configuration component (for example, dxo-master-detail), use the following code:

<dxo-master-detail [template]="'masterDetail'"></dxo-master-detail>

Note that some options with an object type are not implemented as nested components - for example, editorOptions of dxDataGrid, editorOptions of dxForm, the widget option of dxToolbar.

Accessing a DevExtreme Widget Instance

You can access a DevExtreme widget instance using the @ViewChild or @ViewChildren decorator (depending on whether you are getting just one or several instances of one widget) and the component's 'instance' property. Both decorators accept a component name or a template reference variable. In the example below, the refresh method of the dxDataGrid is called:

import { Component, ViewChild } from '@angular/core';
import { DxDataGridComponent } from "devextreme-angular";

@Component({
    selector: 'my-app',
    template: `
        <dx-data-grid #targetDataGrid [dataSource]="dataSource"></dx-data-grid>
        <dx-button text="Refresh data" (onClick)="refresh()"></dx-button>
    `
})
export class AppComponent implements OnChanges {
    @ViewChild(DxDataGridComponent) dataGrid:DxDataGridComponent
    // or
    // @ViewChild("targetDataGrid") dataGrid: DxDataGridComponent
    refresh() {
        this.dataGrid.instance.refresh();
    }
}

To access a DevExtreme widget instance in markup, you can use the same template reference variables. The following example demonstrates how you can get a dxSelectBox value in the template.

<dx-select-box #selectbox [items]="items"></dx-select-box>
{{selectbox.value}}

Angular Change Detection

By default, in Angular, options changes are checked on each user action. If you bind a widget option to this function, it should return a static object. Otherwise, Angular considers that the option is constantly changed after each user action. Alternatively, you can change the default behavior and set the ChangeDetectionStrategy component option to "OnPush".

import {Component, ChangeDetectionStrategy} from '@angular/core';

@Component({
    selector: 'my-app',
    ....
    changeDetection: ChangeDetectionStrategy.OnPush
})

Demos

API Reference

DevExtreme Angular components mirror DevExtreme JavaScript API but use Angular syntax for specifying widget options, subscribing to events and custom templates declaration.

Bundle Size Optimization

Bundlers with Tree Shaking Support

Tree shaking can greatly reduce the downloaded size of the application by removing unused portions of both source and library code. There are a number of bundlers with tree shaking support, such as Webpack 2, Rollup, SystemJS Bundler, etc. Due to specifics of the tree shaking algorithm, your project typescript sources should be prepared accordingly to make tree shaking available. This preparations are performed by the Angular Compiler. You can follow one of the existing guides to configure tree shaking with your bundler (Webpack 2, Angular CLI, Rollup).

To make it work with DevExtreme Angular package, you just need to import only the modules required in your application, not the whole DevExtremeModule. For instance, you can import only DxButtonModule as follows:

import { DxButtonModule } from 'devextreme-angular';

Note, AOT Compilation also decreases a bundle size by precompiling your HTML templates. So, the markup and the template compiler are not included into the final bundle.

Bundlers without Tree Shaking Support

If you are not going to configure tree shaking, you can optimize your bundle size by using imports from specific modules, not from the main 'devextreme-angular' module. You can do this as follows:

import { DxButtonModule } from 'devextreme-angular/ui/button';

Server-side Rendering

Currently, DevExtreme components do not support server side rendering (check this issue). So, you are required to switch this feature off.

License

Familiarize yourself with the DevExtreme License. Free trial is available!

DevExtreme Angular components are released as a MIT-licensed (free and open-source) add-on to DevExtreme.

Support & Feedback

23.1.9

2 months ago

23.2.5

2 months ago

22.1.13

3 months ago

22.2.11

3 months ago

23.1.8

3 months ago

23.2.4

3 months ago

22.1.12

5 months ago

23.1.7

5 months ago

22.2.10

5 months ago

21.2.15

5 months ago

23.2.3

5 months ago

22.1.11

8 months ago

23.2.2-beta

6 months ago

22.2.9

7 months ago

22.2.8

8 months ago

23.1.5

8 months ago

23.1.4

10 months ago

23.1.6

7 months ago

22.1.10

10 months ago

22.2.7

10 months ago

21.2.14

10 months ago

23.1.3

11 months ago

23.1.2-beta

11 months ago

23.1.2-beta.2

11 months ago

22.1.9

1 year ago

22.2.6

1 year ago

20.1.17

1 year ago

20.2.13

1 year ago

21.2.13

1 year ago

21.1.12

1 year ago

22.2.5

1 year ago

22.1.8

1 year ago

22.1.7

1 year ago

22.2.4

1 year ago

22.2.3

1 year ago

21.2.12

1 year ago

20.1.16

2 years ago

19.1.16

2 years ago

19.2.15

2 years ago

18.2.18

2 years ago

20.2.12

2 years ago

22.2.2-beta

1 year ago

22.1.6

2 years ago

21.2.11

2 years ago

21.1.11

2 years ago

22.1.5

2 years ago

21.2.10

2 years ago

21.2.9

2 years ago

22.1.4

2 years ago

22.1.3

2 years ago

21.1.10

2 years ago

21.2.8

2 years ago

22.1.2-beta

2 years ago

20.1.15

2 years ago

19.1.15

2 years ago

19.2.14

2 years ago

18.2.17

2 years ago

20.2.11

2 years ago

21.1.9

2 years ago

21.2.7

2 years ago

21.2.6

2 years ago

20.1.14

2 years ago

19.1.14

2 years ago

19.2.13

2 years ago

18.2.16

2 years ago

20.2.10

2 years ago

18.1.17

2 years ago

21.1.8

2 years ago

21.1.7

2 years ago

21.2.4

2 years ago

21.2.5

2 years ago

17.2.18

2 years ago

21.2.3

3 years ago

21.2.2-beta

3 years ago

21.1.6

3 years ago

20.2.9

3 years ago

21.1.5

3 years ago

20.1.13

3 years ago

20.2.8

3 years ago

21.1.4

3 years ago

21.1.3

3 years ago

20.1.12

3 years ago

20.2.7

3 years ago

19.1.13

3 years ago

17.2.17

3 years ago

19.2.12

3 years ago

18.2.15

3 years ago

18.1.16

3 years ago

21.1.2-beta

3 years ago

20.1.11

3 years ago

20.2.6

3 years ago

20.1.10

3 years ago

20.2.5

3 years ago

19.2.11

3 years ago

20.2.4

3 years ago

20.1.9

3 years ago

20.2.3

4 years ago

18.1.15

4 years ago

17.2.16

4 years ago

20.1.8

4 years ago

19.2.10

4 years ago

19.1.12

4 years ago

18.2.14

4 years ago

20.2.2-beta

4 years ago

20.1.7

4 years ago

20.1.6

4 years ago

20.1.5

4 years ago

19.2.9

4 years ago

18.1.14

4 years ago

17.2.15

4 years ago

20.1.4

4 years ago

18.2.13

4 years ago

19.2.8

4 years ago

19.1.11

4 years ago

20.1.3

4 years ago

20.1.2-beta

4 years ago

18.1.13

4 years ago

19.1.10

4 years ago

17.2.14

4 years ago

18.2.12

4 years ago

19.2.7

4 years ago

19.2.6

4 years ago

19.1.9

4 years ago

19.2.5

4 years ago

19.2.4

4 years ago

19.1.8

4 years ago

18.2.11

4 years ago

19.2.3

5 years ago

19.1.7

5 years ago

19.2.2-beta

5 years ago

19.1.6

5 years ago

18.2.10

5 years ago

19.1.5

5 years ago

19.1.4

5 years ago

18.1.12

5 years ago

18.2.9

5 years ago

18.2.9-pre-19149

5 years ago

19.1.3

5 years ago

18.2.9-pre-19135

5 years ago

18.2.9-pre-19128

5 years ago

18.2.8

5 years ago

19.1.2-beta

5 years ago

18.1.11

5 years ago

18.2.8-pre-19107

5 years ago

18.2.8-pre-19091

5 years ago

18.2.8-pre-19081

5 years ago

18.2.8-pre-19080

5 years ago

18.2.8-pre-19082

5 years ago

17.1.15

5 years ago

17.2.13

5 years ago

18.1.10

5 years ago

18.2.7

5 years ago

18.1.9

5 years ago

18.1.8

5 years ago

17.1.14

5 years ago

17.2.12

5 years ago

18.2.6

5 years ago

18.2.5

5 years ago

18.2.4

5 years ago

18.2.4-beta.2

5 years ago

18.2.4-beta.1

5 years ago

18.2.3

5 years ago

17.2.11

6 years ago

17.1.13

6 years ago

18.2.2-beta.2

6 years ago

18.1.7

6 years ago

18.1.7-beta.4

6 years ago

18.1.7-beta.3

6 years ago

18.2.2-beta.1

6 years ago

18.1.7-beta.2

6 years ago

18.2.1-beta.7

6 years ago

18.2.1-beta.6

6 years ago

18.2.1-beta.5

6 years ago

18.2.1-beta.4

6 years ago

18.1.7-beta.1

6 years ago

18.2.1-beta.3

6 years ago

18.1.6

6 years ago

17.2.10

6 years ago

18.2.1-beta.2

6 years ago

18.2.1-beta.1

6 years ago

18.1.5

6 years ago

18.1.5-beta.3

6 years ago

18.1.5-beta.2

6 years ago

17.2.9

6 years ago

18.1.5-beta.1

6 years ago

17.1.12

6 years ago

18.1.4

6 years ago

18.1.4-beta.2

6 years ago

18.1.4-beta.1

6 years ago

18.1.3

6 years ago

17.2.8

6 years ago

18.1.2-beta.1

6 years ago

18.1.1-beta.6

6 years ago

18.1.1-beta.5

6 years ago

18.1.1-beta.4

6 years ago

17.2.7

6 years ago

18.1.1-beta.3

6 years ago

18.1.1-beta.2

6 years ago

17.1.10

6 years ago

17.2.6

6 years ago

18.1.1-beta.1

6 years ago

17.2.5

6 years ago

17.2.5-beta.1

6 years ago

17.1.9

6 years ago

17.2.4

6 years ago

17.2.4-beta.1

6 years ago

17.1.9-beta.2

6 years ago

17.2.3

6 years ago

17.1.9-beta.1

6 years ago

17.1.8

6 years ago

17.2.2-beta.1

6 years ago

17.2.1-beta.4

7 years ago

17.2.1-beta.3

7 years ago

17.2.1-beta.2

7 years ago

17.1.7

7 years ago

17.1.7-rc.2

7 years ago

17.2.1-beta.1

7 years ago

17.1.7-rc.1

7 years ago

17.1.6

7 years ago

16.2.9

7 years ago

17.1.5

7 years ago

17.1.5-rc.1

7 years ago

16.2.8

7 years ago

17.1.4

7 years ago

16.2.7

7 years ago

17.1.3

7 years ago

17.1.2-beta.1

7 years ago

16.2.6

7 years ago

16.2.6-rc.1

7 years ago

16.2.5

7 years ago

16.2.5-rc.1

7 years ago

16.2.4

7 years ago

16.2.4-rc.5

7 years ago

16.2.3-rc.4

7 years ago

16.2.3-rc.3

7 years ago

16.2.3-rc.2

7 years ago

16.2.3-rc.1

7 years ago

16.2.2-beta.2

7 years ago

16.2.2-beta.1

7 years ago

16.2.1-alpha.3

7 years ago

16.2.1-alpha.2

7 years ago