Angular UI Components Documentation

Angular DataTable Component

The DataTable component for Angular represents a lightweight Table widget built to easily replace your HTML Tables.

1. Installation

The easiest way to get started with jQWidgets UI for Angular is to use the Angular CLI Tool. To scaffold your project structure, follow its installation instructions.

npm install -g @angular/cli
ng new jqwidgets-project
cd jqwidgets-project

Install jQWidgets

jQWidgets Angular UI comes packaged with Angular CLI schematics to make creating Angular applications easier. Schematics are included with both @angular/cdk and jqwidgets-ng. Once you install the npm packages, they will be available through the Angular CLI.

Angular CLI supports the addition of packages through the ng add command. The ng add command provides faster and more user-friendly package installation. To install the jQWidgets UI for Angular package, use ng add and add the name of the NPM package:

ng add jqwidgets-ng

Alternatively, you can use the standard installation (Manual Setup)

jQWidgets UI for Angular is distributed as jqwidgets-ng NPM package

  1. Download and install the package.
    npm install jqwidgets-ng
  2. Adding CSS reference

    The following CSS file is available in ../node_modules/jqwidgets-ng/ package folder. This can be referenced in [src/styles.css] using following code.

    @import 'jqwidgets-ng/jqwidgets/styles/jqx.base.css';

    Another way to achieve the same is to edit the angular.json file and in the styles add the style.

    "styles": [
    	"node_modules/jqwidgets-ng/jqwidgets/styles/jqx.base.css"
    ]
    

2. Add the HTML for jQWidgets component in src/app/app.component.html

app.component.html


<jqxDataTable [theme]="'fluent'"
    [width]="getWidth()" [columns]="columns" [selectionMode]="'singleRow'"
    [altRows]="true" [sortable]="true" [editable]="true">
      <table id='table' border='1'>
        <thead>
          <tr>
            <th align='left'>First Name</th>
            <th align='left'>Last Name</th>
            <th align='left'>Product</th>
            <th align='right'>Price</th>
            <th align='right'>Quantity</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>Ian</td>
            <td>Devling</td>
            <td>Espresso Truffle</td>
            <td>$1.75</td>
            <td>8</td>
          </tr>
          <tr>
            <td>Nancy</td>
            <td>Wilson</td>
            <td>Cappuccino</td>
            <td>$5.00</td>
            <td>3</td>
          </tr>
          <tr>
            <td>Cheryl</td>
            <td>Nodier</td>
            <td>Caffe Americano</td>
            <td>$2.50</td>
            <td>4</td>
          </tr>
          <tr>
            <td>Martin</td>
            <td>Saavedra</td>
            <td>Caramel Latte</td>
            <td>$3.80</td>
            <td>11</td>
          </tr>
          <tr>
            <td>Guylene</td>
            <td>Bjorn</td>
            <td>Green Tea</td>
            <td>$1.50</td>
            <td>8</td>
          </tr>
          <tr>
            <td>Andrew</td>
            <td>Burke</td>
            <td>Caffe Espresso</td>
            <td>$3.00</td>
            <td>2</td>
          </tr>
          <tr>
            <td>Regina</td>
            <td>Murphy</td>
            <td>White Chocolate Mocha</td>
            <td>$3.60</td>
            <td>6</td>
          </tr>
          <tr>
            <td>Michael</td>
            <td>Murphy</td>
            <td>Caramel Latte</td>
            <td>$3.80</td>
            <td>2</td>
          </tr>
          <tr>
            <td>Petra</td>
            <td>Bein</td>
            <td>Caffe Americano</td>
            <td>$2.50</td>
            <td>7</td>
          </tr>
          <tr>
            <td>Nancy</td>
            <td>Nodier</td>
            <td>Caffe Latte</td>
            <td>$4.50</td>
            <td>10</td>
          </tr>
          <tr>
            <td>Peter</td>
            <td>Devling</td>
            <td>Green Tea</td>
            <td>$1.50</td>
            <td>1</td>
          </tr>
          <tr>
            <td>Beate</td>
            <td>Saylor</td>
            <td>Espresso con Panna</td>
            <td>$3.25</td>
            <td>3</td>
          </tr>
          <tr>
            <td>Shelley</td>
            <td>Nodier</td>
            <td>Peppermint Mocha Twist</td>
            <td>$4.00</td>
            <td>7</td>
          </tr>
          <tr>
            <td>Nancy</td>
            <td>Murphy</td>
            <td>Peppermint Mocha Twist</td>
            <td>$4.00</td>
            <td>1</td>
          </tr>
          <tr>
            <td>Lars</td>
            <td>Wilson</td>
            <td>Caffe Espresso</td>
            <td>$3.00</td>
            <td>11</td>
          </tr>
        </tbody>
      </table>
</jqxDataTable>

	

3. Setup Component Logic

app.component.ts


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

import { jqxDataTableModule, jqxDataTableComponent } from 'jqwidgets-ng/jqxdatatable';
@Component({
    selector: 'app-root',
    imports: [jqxDataTableModule],
    standalone: true,
    templateUrl: './app.component.html'
})

export class AppComponent {

    getWidth(): any {
        if (document.body.offsetWidth < 850) {
            return '90%';
        }

        return 850;
    }

    columns: any[] =
        [
            { text: 'First Name', dataField: 'First Name', width: 200 },
            { text: 'Last Name', dataField: 'Last Name', width: 200 },
            { text: 'Product', dataField: 'Product', width: 250 },
            { text: 'Unit Price', dataField: 'Price', width: 100, align: 'right', cellsAlign: 'right', cellsFormat: 'c2' },
            { text: 'Quantity', dataField: 'Quantity', width: 100, align: 'right', cellsAlign: 'right', cellsFormat: 'n' }
        ];
}

Summary

jQWidgets UI for Angular provides an easy way to integrate robust UI components into your Angular project. By using either the ng add command or manual setup, you can quickly get started. Once the setup is complete, you can add the desired jQWidgets components and configure them in your Angular components to match your application requirements.

DataTable API

API Reference of the jQWidgets DataTable component for Angular: DataTable API