DevExtreme jQuery/JS - First Steps

This step-by-step tutorial guides you through building a simple task list application with a progress bar. The completed application looks as follows:

Embedded applications are not available for the selected DevExtreme version (v25.1).
We recommend that you upgrade to the most recent version of DevExtreme to access the latest features, bug fixes, and security updates.

The application includes two DevExtreme components: DataGrid and ProgressBar. The DataGrid displays tasks, and you can mark them as complete or incomplete. The ProgressBar above the DataGrid indicates task completion progress.

You can find the full source code in the GitHub repository:

View on GitHub

Setup Your Project

Create an empty web application. Then add jQuery and DevExtreme source files to the <head>:

index.html
  • <head>
  • <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  • <script type="text/javascript" src="https://cdn3.devexpress.com/jslib/25.1.15/js/dx.all.js"></script>
  • </head>

For complete installation instructions, refer to the following help topic: Add DevExtreme to a jQuery Application.

Style the App

DevExtreme offers over 40 predefined themes for component styling. You can also create a custom theme with our ThemeBuilder.

In the next step of the tutorial, apply the dx.fluent.blue.light theme and add CSS styles to the components.

To apply a theme, link its file in the <head> between jQuery and DevExtreme sources (the order is important):

index.html
  • <head>
  • <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  • <link rel="stylesheet" href="https://cdn3.devexpress.com/jslib/25.1.15/css/dx.fluent.blue.light.css" />
  • <link rel="stylesheet" type="text/css" href="index.css" />
  • <script type="text/javascript" src="https://cdn3.devexpress.com/jslib/25.1.15/js/dx.all.js"></script>
  • </head>

If you want to apply theme colors and typography settings to all page elements (and not only to DevExtreme UI components), add a dx-viewport class to the <body> tag of your application's index.html file.

To configure component styles, create an index.css file and import it alongside the DevExtreme theme CSS file:

index.css
  • :root {
  • color-scheme: light; /* Update this property when you switch between light/dark themes. */
  • }
  •  
  • #dashboard {
  • display: grid;
  • gap: 20px;
  • max-width: 900px;
  • margin: 40px auto;
  • padding: 80px 20px;
  • box-sizing: border-box;
  • }
  •  
  • #progress,
  • #task-grid {
  • background-color: light-dark(#fff, #383838);
  • padding: 16px;
  • border-radius: 8px;
  • box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  • }

Specify the Page Layout

Next, specify the component layout in the HTML file:

index.html
  • <div id="dashboard">
  • <div id="progress"></div>
  • <div id="task-grid"></div>
  • </div>

The dashboard is the container for two components: ProgressBar and DataGrid.

Configure DataGrid

Now, you will create a DataGrid and configure its main functionality.

Bind DataGrid to Data

The DataGrid component can load and update data from different data source types. In this guide, a small local array serves as the data source. Follow these steps:

  1. Create the tasks array.
  2. Assign the array to the dataSource property.
  3. Specify keyExpr (id in this case).
  4. In the columns array, define which columns you want to display.

    index.js
    • $(() => {
    • const tasks = [
    • { id: 1, task: "Buy groceries", dueDate: new Date(), done: false },
    • { id: 2, task: "Write a blog post", dueDate: new Date(), done: true }
    • ];
    • $("#task-grid").dxDataGrid({
    • dataSource: tasks,
    • keyExpr: "id",
    • columns: ["task", "dueDate", "done"],
    • });
    • });

Configure Editing

The DataGrid component allows you to configure core features such as sorting, filtering, search, grouping, selection, and editing. Enable editing to allow users to add, edit, and delete rows.

This guide explains how to create a task list where users can check off tasks, remove them, and add new ones. To do this, specify the following editing options:

  • allowAdding
    Set to true - allows users to add new rows.

  • allowDeleting
    Set to true - allows users to remove rows.

  • allowUpdating
    Set to true - allows users to update rows.

  • mode
    Change the mode from the default "row" to "cell" for easy task status changes.

  • newRowPosition
    Set new rows to appear at the "last" position for a top-to-bottom task list.

index.js
  • $(() => {
  • $("#task-grid").dxDataGrid({
  • dataSource: tasks,
  • keyExpr: "id",
  • columns: ["task", "dueDate", "done"],
  • editing: {
  • mode: "cell",
  • allowUpdating: true,
  • allowAdding: true,
  • allowDeleting: true,
  • newRowPosition: "last"
  • },
  • });
  • });

Show Progress

At this point of the tutorial, you have created a DataGrid that stores task records and allows users to edit them. To display task progress, you integrated a ProgressBar into the layout. The next steps are to configure the ProgressBar options and synchronize it with DataGrid updates.

Configure ProgressBar

First, create a ProgressBar and save its instance to access its methods later.

Next, set the value option to 50, as half of the tasks in the initial list are completed.

index.js
  • $(() => {
  • const progress = $("#progress").dxProgressBar({
  • value: 50,
  • }).dxProgressBar("instance");
  • });

Sync ProgressBar with DataGrid

To synchronize ProgressBar with DataGrid, define an updateProgress function. This function checks completed tasks and updates the ProgressBar value using the option method. Use this function to handle the following events: onRowUpdated, onRowInserted, and onRowRemoved.

index.js
  • $(() => {
  • $("#task-grid").dxDataGrid({
  • // ...
  • onRowUpdated: updateProgress,
  • onRowInserted: updateProgress,
  • onRowRemoved: updateProgress
  • });
  •  
  • function updateProgress() {
  • const all = tasks.length;
  • const completed = tasks.filter((t) => t.done).length;
  • progress.option("value", Math.round((completed / all) * 100));
  • }
  • });

Customize the App

Apply styles and templates to DevExtreme components to customize your app appearance.

Specify CSS Styles

DevExtreme components assign classes to nested elements. You can specify custom CSS styles for these classes to customize your app. For a list of common DevExtreme classes, refer to the following topic: CSS Classes.

This example applies rounded corners to the first and last rows of the DataGrid:

index.css
  • #task-grid .dx-datagrid-headers, #task-grid .dx-datagrid .dx-datagrid-table .dx-header-row>td:first-child {
  • border-top-left-radius: 8px;
  • }
  •  
  • #task-grid .dx-datagrid-headers, #task-grid .dx-datagrid .dx-datagrid-table .dx-header-row>td:last-child {
  • border-top-right-radius: 8px;
  • }
  •  
  • #task-grid .dx-datagrid-rowsview {
  • border-bottom-left-radius: 8px;
  • border-bottom-right-radius: 8px;
  • border-bottom-style: none;
  • }

DevExtreme defines multiple theme-dependent CSS variables. You can use these variables to customize UI elements. This example applies the --dx-color-danger variable to "Delete" buttons in DataGrid rows:

index.css
  • .dx-link-delete::before {
  • color: var(--dx-color-danger)
  • }

This example also customizes row deletion popups. The following styles stretch the nested Toolbar component to align dialog buttons with the dialog text:

index.css
  • .dx-dialog .dx-toolbar-center {
  • margin: -8px !important;
  • width: calc(100% + 16px);
  • border-spacing: 8px 0;
  • float: none !important;
  • }
  •  
  • .dx-toolbar-center .dx-button {
  • width: 100%;
  • }
  •  
  • .dx-toolbar-center .dx-item {
  • padding-right: 0 !important;
  • }

Configure Templates

DevExtreme components allow you to specify custom markup for certain elements. To specify custom markup, configure templates.

This example hides the DataGrid toolbar and specifies a columns[].headerCellTemplate to display an "Add a row" button in the header row. Integrate a DevExtreme Button within this template and call DataGrid.addRow() in the button's onClick handler:

index.js
  • $("#task-grid").dxDataGrid({
  • columns: [{
  • type: 'buttons',
  • headerCellTemplate(el, data) {
  • return $('<div>').dxButton({
  • icon: 'add',
  • stylingMode: 'text',
  • onClick() {
  • data.component.addRow();
  • }
  • })
  • }
  • }],
  • toolbar: {
  • visible: false,
  • },
  • // ...
  • });

This example also configures columns[].cellTemplate to implement placeholder values for empty cells and format date values (formatDate()):

index.js
  • $("#task-grid").dxDataGrid({
  • columns: [{
  • dataField: "task",
  • cellTemplate(element, data) {
  • if (!data.value) {
  • return $(element)
  • .text('Enter a title...')
  • .css('color', 'var(--dx-color-icon)');
  • } else {
  • return $(element).text(data.value);
  • }
  • }
  • }, {
  • dataField: "dueDate",
  • cellTemplate(element, data) {
  • if (!data.value) {
  • return $(element)
  • .text('Enter a date...')
  • .css('color', 'var(--dx-color-icon)');
  • } else {
  • return $(element).text(DevExpress.localization.formatDate(data.value, 'shortDate'));
  • }
  • }
  • }],
  • // ...
  • });

You can find the full source code of this example in the following GitHub repository:

View on GitHub

Explore More

To learn more about DevExtreme, refer to the following sources:

  1. Learn the basics with Component Configuration Syntax.

  2. Edit and copy code from over 450 DevExtreme demos.

  3. To learn more about a specific component, review guides and API references in the documentation. For common issues, refer to the following resources:

  4. Need help? Submit a ticket to the DevExpress Support Center.