DevExpress (DevExtreme) DataGrid component in Angular application (2024)

DevExpress (DevExtreme) DataGrid component in Angular application (2)

DevExpress is a set of tools and controls that help create a graphical user interface, and it offers many HTML5 / JS widgets. This saves time for the programmer and is also very easy to adjust as needed.

DevExtreme is a component suite for creating highly responsive web applications for touch devices and traditional desktops. The suite includes 50+ UI components ready to use with jQuery, Angular, AngularJS, Knockout, ASP.NET MVC or ASP.NET Core: data grid, interactive charts, data editors, navigation and multi-purpose widgets designed to look and behave harmoniously in any browser.Source

The integration of DevExtreme components and the Angular project is very easy. You need to add the latest version of DevExtreme package to an already created Angular application:

$ npm install devextreme@19.1 devextreme-angular@19.1 –save –save-exact

allowing DevExpress components to be used.

DevExpress (DevExtreme) DataGrid component in Angular application (3)

After trying to start a project, we get the following message:

DevExpress (DevExtreme) DataGrid component in Angular application (4)

To resolve this issue, we need to install the stream using the $ npm install stream command.

The next step is to add dx.common.css and dx.light.css to the angular.json file within ‘styles’ to apply the default theme to the components you want.

The theme can be selected from the official site.

DevExpress (DevExtreme) DataGrid component in Angular application (5)

The last thing to do to be able to use DevExtreme components is to add to the ngModule the name of the component we want to display. In this example, this is DxDataGridModule, and we do this as follows:

DevExpress (DevExtreme) DataGrid component in Angular application (6)

We then create a table in HTML and get the following result.
The view shows a created table of data that can be filtered by any parameter and sorted as desired. Thus, it is possible to automatically sort and filter the data by importing the DevExtreme component. Data manipulation is very simple.

DevExpress (DevExtreme) DataGrid component in Angular application (7)

In order to influence the look of the table, it is necessary to use the pseudoclass selector “ng-deep“. (Otherwise, if we have multiple components, we need to add ‘: host’ before:: ng-deep in order for CSS to be applied solely to that component, not globally. But since this example has only one component, we’ll leave it like this.

Using the following code will make the table header dark gray and the header names bold:

DevExpress (DevExtreme) DataGrid component in Angular application (8)

The next item is to enable the deletion and editing of data. This must be done within the tags specifying the editing method, and it is also possible to determine individually whether to delete, edit or add a new row using true/false values.
This seems to be a “mode” command.
In our example, editing, adding and deleting in the popup window is enabled, and besides it, there are also row mode, batch mode, cell mode, and form mode.

DevExpress (DevExtreme) DataGrid component in Angular application (9)

At the foot of the table, a summary of each column can be added. “TotalItems array”. The simplest way is to pass the name of the column you want to summarize and how depending on what data you want to retrieve. In this example, you will see a summary by a number of users, located below the “Ime” column. Also, the view shows how the number increases dynamically, that is, depending on adding new users or deleting existing users.

DevExpress (DevExtreme) DataGrid component in Angular application (10)

DisplayFormat is intended only to specify what it will write at the foot of the table, instead of the predefined “Sum / Count…” DevExtreme format, while passing {0} the value we want to display.

DevExpress (DevExtreme) DataGrid component in Angular application (11)

If an additional hover effect is to be applied to an element within a component, the method (onCellHoverChanged) = “hover ($ event)
within the dx-data-grid tag in an HTML document, while within the .ts component this method should be defined as follows:

DevExpress (DevExtreme) DataGrid component in Angular application (12)

The above method shows several conditions by which we tell the component that if the row type is ‘data‘ (this is necessary so that the effect does not refer to the titles or table header) and if it is a ‘Ime‘ column then we want to event mouseover results in the information inside the selected cell element being Bold and colored yellow, otherwise the color will be black and fontWeight normal.

DevExpress (DevExtreme) DataGrid component in Angular application (13)

In our example, we will add another column called ” Broj stanovnika po km2 (Population per km2)“. We will do this as follows. In order to add potency to a column name, we need to assign a “template” [headerCellTemplate] to the desired column in the HTML document, where we pass it a name as desired. After defining the column and specifying the format of the data in the table (type: ‘fixedPoint‘, precision: 0), we need to say what we want to do from that header. Therefore, in dxTemplate, within the element, we specify the name of the column as desired, with an additional tag between which we enter the number that we want to be displayed as potency. The rest is pure CSS.

DevExpress (DevExtreme) DataGrid component in Angular application (14)

Now it is necessary to determine in CSS what dimensions we want this number to have, and we do this by first specifying the table id (#gridContainer) and the affected element (sup) with the pseudoclass selector ‘ng-deep‘.

DevExpress (DevExtreme) DataGrid component in Angular application (15)

The result is:

DevExpress (DevExtreme) DataGrid component in Angular application (16)

This would be a simplified representation of the use of the DevExtreme data grid component in the Angular project. In another post, we will look at other components and their implementation.

Web site: https://www.alenibric.com.tr

DevExpress (DevExtreme) DataGrid component in Angular application (2024)
Top Articles
Latest Posts
Article information

Author: Duncan Muller

Last Updated:

Views: 6693

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Duncan Muller

Birthday: 1997-01-13

Address: Apt. 505 914 Phillip Crossroad, O'Konborough, NV 62411

Phone: +8555305800947

Job: Construction Agent

Hobby: Shopping, Table tennis, Snowboarding, Rafting, Motor sports, Homebrewing, Taxidermy

Introduction: My name is Duncan Muller, I am a enchanting, good, gentle, modern, tasty, nice, elegant person who loves writing and wants to share my knowledge and understanding with you.