Angular UI Components Documentation
A jQWidgets theme is a stylesheet and a name. The stylesheet jqx.fluent.css styles every widget whose theme is fluent: the widget adds the name to its CSS classes, such as jqx-grid-fluent, and the stylesheet's rules match those classes. In Angular you add the stylesheet to angular.json and set the theme input of each component.
This guide does that in a project made with Angular CLI 22 (ng new) and jqwidgets-ng 27.0.1, and then switches between a light and a dark theme while the app runs. The project setup is described in Angular CLI with jQWidgets. The theme list below is for 27.1.0, the current release; the notes that name 27.0.1 describe that version.
jqwidgets-ng installs the stylesheets in node_modules/jqwidgets-ng/jqwidgets/styles/. jqx.base.css holds the layout rules every widget needs and is always loaded first. Each other file is one theme, and the theme's name is the file name without jqx. and .css.
| Kind | Theme names in jqwidgets-ng 27.1.0 |
|---|---|
| Design systems | fluent, fluent-dark, material, material-dark, material-green, material-green-dark, material-purple, material-purple-dark, tailwind, tailwind-dark, tailwind-blue, tailwind-blue-dark, bootstrap |
| Light and dark pairs | fluent and fluent-dark, material and material-dark, material-green and material-green-dark, material-purple and material-purple-dark, tailwind and tailwind-dark, tailwind-blue and tailwind-blue-dark, light and dark, metro and metrodark, ui-lightness and ui-darkness |
| Other dark themes | black, android, blue, windowsphone, ui-le-frog |
| Other light themes | arctic, blackberry, classic, darkblue, energyblue, flat, fresh, glacier, highcontrast, mobile, office, orange, shinyblack, summer, web, ui-overcast, ui-redmond, ui-smoothness, ui-start, ui-sunny |
| Legacy files | jqx.light-ie.css and jqx.dark-ie.css (theme names light and dark), jqx.fluent_old.css (theme name fluent) |
Version 27.1.0 added fluent-dark, material-dark, material-green-dark and material-purple-dark, and the tailwind-blue pair: Tailwind with the blue of Microsoft 365. Each dark theme has the same sizes and spacing as its light theme, so nothing moves when the app switches between them. Version 27.0.1 has none of them; there, use tailwind-dark for a dark look.
The legacy files are for existing apps. jqx.light-ie.css and jqx.dark-ie.css are light and dark written without CSS variables. jqx.fluent_old.css is an earlier version of fluent with the same class names, so load one or the other.
Add the base stylesheet and the theme to the styles of the build target in angular.json, in this order:
"styles": [
"node_modules/jqwidgets-ng/jqwidgets/styles/jqx.base.css",
"node_modules/jqwidgets-ng/jqwidgets/styles/jqx.fluent.css",
"src/styles.css"
]
The theme has to come after jqx.base.css: both stylesheets style the same elements, and the later one wins. ng serve reads angular.json only when it starts, so restart it.
Every jqwidgets-ng component has a theme input. Give it the theme's name:
src/app/app.ts:
import { Component } from '@angular/core';
import { jqxGridModule } from 'jqwidgets-ng/jqxgrid';
@Component({ selector: 'app-root', imports: [jqxGridModule], templateUrl: './app.html' })
export class App {
readonly source = new jqx.dataAdapter({
localdata: [
{ name: 'Espresso', category: 'Coffee', price: 2.2, stock: 140 },
{ name: 'Cappuccino', category: 'Coffee', price: 3.1, stock: 85 },
{ name: 'Flat White', category: 'Coffee', price: 3.4, stock: 62 },
{ name: 'Green Tea', category: 'Tea', price: 2.5, stock: 120 },
{ name: 'Chai Latte', category: 'Tea', price: 3.6, stock: 40 },
{ name: 'Hot Chocolate', category: 'Chocolate', price: 3.2, stock: 75 },
{ name: 'Croissant', category: 'Bakery', price: 2.4, stock: 30 },
{ name: 'Blueberry Muffin', category: 'Bakery', price: 2.9, stock: 18 }
],
datatype: 'array',
datafields: [
{ name: 'name', type: 'string' },
{ name: 'category', type: 'string' },
{ name: 'price', type: 'number' },
{ name: 'stock', type: 'number' }
]
});
readonly columns = [
{ text: 'Product', datafield: 'name' },
{ text: 'Category', datafield: 'category', width: 130 },
{
text: 'Price',
datafield: 'price',
width: 90,
cellsformat: 'c2',
cellsalign: 'right',
align: 'right'
},
{ text: 'In stock', datafield: 'stock', width: 90, cellsalign: 'right', align: 'right' }
];
}
src/app/app.html:
<jqxGrid
[theme]="'fluent'"
[width]="560"
[autoheight]="true"
[sortable]="true"
[source]="source"
[columns]="columns">
</jqxGrid>
The value of a [theme] binding is an expression, so a fixed name needs the inner quotes: [theme]="'fluent'". Without the brackets, theme="fluent" sets the same string. Each component needs its own theme; a widget without one uses only jqx.base.css.
To let users change the theme, the app needs two things: the new theme's stylesheet on the page, and the new name in every component's theme input. A service can do both, keeping the name in a signal that the templates read.
Themes that are loaded later go in angular.json with "inject": false. The build then writes each to its own file, named by bundleName, and does not add it to the page:
"styles": [
"node_modules/jqwidgets-ng/jqwidgets/styles/jqx.base.css",
{
"input": "node_modules/jqwidgets-ng/jqwidgets/styles/jqx.fluent.css",
"bundleName": "jqx.fluent",
"inject": false
},
{
"input": "node_modules/jqwidgets-ng/jqwidgets/styles/jqx.tailwind.css",
"bundleName": "jqx.tailwind",
"inject": false
},
{
"input": "node_modules/jqwidgets-ng/jqwidgets/styles/jqx.tailwind-dark.css",
"bundleName": "jqx.tailwind-dark",
"inject": false
},
"src/styles.css"
]
The build copies the images and fonts the themes refer to, so the files work as they are. ng build writes them to dist/<project>/browser/jqx.fluent.css and so on, without a hash in the name.
Several themes, such as fluent, tailwind and tailwind-dark, set CSS variables with the same names on :root. If two of them are on the page, the one loaded last decides the colours of both: after tailwind-dark has been loaded, a fluent grid turns dark. So the service adds the new theme's <link>, waits until it has loaded, and then removes the previous one.
src/app/theme.service.ts:
import { DOCUMENT, Injectable, inject, signal } from '@angular/core';
@Injectable({ providedIn: 'root' })
export class ThemeService {
private readonly document = inject(DOCUMENT);
private link?: HTMLLinkElement;
readonly theme = signal('');
async use(name: string): Promise<void> {
const link = this.document.createElement('link');
link.rel = 'stylesheet';
link.href = `jqx.${name}.css`;
await new Promise<void>((resolve, reject) => {
link.onload = () => resolve();
link.onerror = () => reject(new Error(`${link.href} could not be loaded`));
this.document.head.appendChild(link);
});
// A theme stylesheet sets CSS variables on :root, so keep only one on the page.
this.link?.remove();
this.link = link;
this.theme.set(name);
this.document.body.classList.toggle('dark', name.endsWith('-dark'));
}
}
The signal changes only after the stylesheet has loaded, so the widgets never show the new theme's classes without its rules. The dark class on <body> lets the page itself follow the theme, as shown below.
The first theme is loaded the same way, before the application starts. provideAppInitializer in src/app/app.config.ts waits for it:
import { ApplicationConfig, inject, provideAppInitializer, provideBrowserGlobalErrorListeners } from '@angular/core';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
import { ThemeService } from './theme.service';
export const appConfig: ApplicationConfig = {
providers: [
provideBrowserGlobalErrorListeners(),
provideRouter(routes),
// Load the first theme before the app renders.
provideAppInitializer(() => inject(ThemeService).use('fluent'))
]
};
The component injects the service and reads its signal in the template. When the signal changes, Angular updates the theme input and the grid draws itself again with the new classes.
src/app/app.ts:
import { Component, inject } from '@angular/core';
import { jqxGridModule } from 'jqwidgets-ng/jqxgrid';
import { ThemeService } from './theme.service';
@Component({
selector: 'app-root',
imports: [jqxGridModule],
templateUrl: './app.html',
styleUrl: './app.css'
})
export class App {
readonly themeService = inject(ThemeService);
readonly themes = ['fluent', 'tailwind', 'tailwind-dark'];
readonly source = new jqx.dataAdapter({
localdata: [
{ name: 'Espresso', category: 'Coffee', price: 2.2, stock: 140 },
{ name: 'Cappuccino', category: 'Coffee', price: 3.1, stock: 85 },
{ name: 'Flat White', category: 'Coffee', price: 3.4, stock: 62 },
{ name: 'Green Tea', category: 'Tea', price: 2.5, stock: 120 },
{ name: 'Chai Latte', category: 'Tea', price: 3.6, stock: 40 },
{ name: 'Hot Chocolate', category: 'Chocolate', price: 3.2, stock: 75 },
{ name: 'Croissant', category: 'Bakery', price: 2.4, stock: 30 },
{ name: 'Blueberry Muffin', category: 'Bakery', price: 2.9, stock: 18 }
],
datatype: 'array',
datafields: [
{ name: 'name', type: 'string' },
{ name: 'category', type: 'string' },
{ name: 'price', type: 'number' },
{ name: 'stock', type: 'number' }
]
});
readonly columns = [
{ text: 'Product', datafield: 'name' },
{ text: 'Category', datafield: 'category', width: 130 },
{
text: 'Price',
datafield: 'price',
width: 90,
cellsformat: 'c2',
cellsalign: 'right',
align: 'right'
},
{ text: 'In stock', datafield: 'stock', width: 90, cellsalign: 'right', align: 'right' }
];
}
src/app/app.html:
<label class="toolbar">
Theme
<select #picker (change)="themeService.use(picker.value)">
@for (name of themes; track name) {
<option [value]="name" [selected]="name === themeService.theme()">{{ name }}</option>
}
</select>
</label>
<jqxGrid
[theme]="themeService.theme()"
[width]="560"
[autoheight]="true"
[sortable]="true"
[source]="source"
[columns]="columns">
</jqxGrid>
The picker is a native <select>; its change event calls the service with the chosen name.
A theme styles the widgets, not the page around them. src/styles.css gives the page dark colours when the service sets the dark class; color-scheme makes the browser draw native controls, such as the <select>, dark as well:
body {
margin: 24px;
font-family: system-ui, sans-serif;
color-scheme: light;
background: #ffffff;
color: #1f2937;
}
body.dark {
color-scheme: dark;
background: #14171c;
color: #e5e7eb;
}
In jqwidgets-ng 27.0.1, a component sometimes ignores a changed input. When an input changes, the component applies its inputs in a fixed order and stops at the first array input whose items equal the widget's current value. On a jqxDropDownList, [source] comes before [theme], so with an unchanged list of items a new theme is never applied. jqxGrid applies theme before source and columns, so the grid above is not affected.
If a component keeps its old theme, set the theme with the component's theme() method from an effect, which runs again whenever the signal changes:
import { Component, effect, signal, viewChild } from '@angular/core';
import { jqxDropDownListComponent, jqxDropDownListModule } from 'jqwidgets-ng/jqxdropdownlist';
@Component({
selector: 'app-root',
imports: [jqxDropDownListModule],
template: `
<jqxDropDownList
#sizeList
[theme]="theme()"
[source]="sizes"
[width]="200"
[height]="32"
></jqxDropDownList>
<button type="button" (click)="theme.set('tailwind-dark')">Dark theme</button>
`
})
export class App {
readonly sizeList = viewChild.required<jqxDropDownListComponent>('sizeList');
readonly theme = signal('fluent');
readonly sizes = ['Small', 'Medium', 'Large'];
constructor() {
// jqwidgets-ng 27.0.1 does not apply [theme] here (see the note above): set it with the method.
effect(() => this.sizeList().theme(this.theme()));
}
}
angular.json (or loaded by the service) and that the name in theme matches the file name: jqx.tailwind-dark.css is tailwind-dark.jqx.base.css is loaded after the theme. Put it first in styles.<link> when you load the next one.ng build fails with "bundle initial exceeded maximum budget". A new project allows a first bundle of 1 MB, and this app's is about 2 MB. Raise the initial budget of the production configuration in angular.json, for example to "maximumWarning": "3MB" and "maximumError": "4MB".*zoom: 1; current browsers ignore them, and so can you.More: Angular CLI with jQWidgets, the Angular Grid tutorials, and the unit testing guide.