Angular UI Components Documentation
With GraphQL, the client says exactly which fields it wants and sends its arguments as typed variables. This tutorial connects an Angular jqxGrid to a GraphQL API with nothing but fetch: a query brings one page of orders, sorted and filtered on the server, and a mutation saves each edit. It builds the API too, with GraphQL Yoga on Node.js; the grid's side works the same with any GraphQL server, such as Apollo Server, Hasura or a .NET or Java one.

You need Node.js 22 or later for the API. Create a project for it, in a folder of its own, and install GraphQL Yoga:
npm init -y
npm install graphql graphql-yoga
npm pkg set type=module
The grid is in an Angular CLI app set up as in Angular CLI with jQWidgets. It needs no GraphQL client library.
Save this as server.js and start it with node server.js. The schema is the contract between the grid and the server: an orders query with an offset, a page size, a sort and a list of filters, which returns the rows of the page and the number of matching orders, and an updateOrder mutation.
// A GraphQL API for the grid: orders a page at a time, sorted and filtered on the
// server, and a mutation that changes an order. GraphQL Yoga, on Node.js.
// node server.js (http://localhost:4000/graphql, or the port in PORT)
import { createServer } from 'node:http';
import { createSchema, createYoga } from 'graphql-yoga';
import { GraphQLError } from 'graphql';
const typeDefs = /* GraphQL */ `
enum OrderField { id customer product quantity price orderDate status }
enum Condition { CONTAINS EQUAL NOT_EQUAL GREATER_THAN LESS_THAN GREATER_THAN_OR_EQUAL LESS_THAN_OR_EQUAL }
enum Status { New Shipped Delivered Cancelled }
type Order {
id: ID!
customer: String!
product: String!
quantity: Int!
price: Float!
orderDate: String!
status: Status!
}
type OrderPage {
rows: [Order!]!
total: Int!
}
input OrderFilter {
field: OrderField!
condition: Condition!
value: String!
}
input OrderSort {
field: OrderField!
descending: Boolean = false
}
type Query {
orders(offset: Int = 0, limit: Int = 20, sort: OrderSort, filters: [OrderFilter!] = []): OrderPage!
}
type Mutation {
updateOrder(id: ID!, quantity: Int, status: Status): Order!
}
`;
// 10,000 orders in memory, to keep the example self-contained; a real API asks its database.
const customers = ['Alfreds Futterkiste', 'Ana Trujillo', 'Antonio Moreno', 'Around the Horn', 'Berglunds snabbköp', 'Blauer See Delikatessen', 'Bólido Comidas', 'Ernst Handel'];
const products = ['Chai', 'Chang', 'Aniseed Syrup', 'Tofu', 'Konbu', 'Pavlova', 'Ikura', 'Queso Cabrales', 'Gnocchi', 'Mozzarella'];
const statuses = ['New', 'Shipped', 'Delivered', 'Cancelled'];
const today = new Date();
const orders = Array.from({ length: 10000 }, (_, k) => {
const i = k + 1;
const date = new Date(today.getFullYear(), today.getMonth(), today.getDate() - (i % 365));
return {
id: String(i),
customer: customers[i % 8],
product: products[(i * 7) % 10],
quantity: 1 + (i * 13) % 50,
price: Math.round(500 + (i * 37) % 9500) / 100,
orderDate: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`,
status: statuses[(i * 3) % 4]
};
});
const numeric = new Set(['quantity', 'price']);
const value = (order, field) => (field === 'id' ? Number(order.id) : order[field]);
function matches(order, { field, condition, value: text }) {
const v = value(order, field);
const want = numeric.has(field) || field === 'id' ? Number(text) : text;
if (typeof want === 'number' && Number.isNaN(want)) return false;
switch (condition) {
case 'CONTAINS': return String(v).toLowerCase().includes(String(want).toLowerCase());
case 'EQUAL': return typeof v === 'string' ? v.toLowerCase() === String(want).toLowerCase() : v === want;
case 'NOT_EQUAL': return typeof v === 'string' ? v.toLowerCase() !== String(want).toLowerCase() : v !== want;
case 'GREATER_THAN': return v > want;
case 'LESS_THAN': return v < want;
case 'GREATER_THAN_OR_EQUAL': return v >= want;
case 'LESS_THAN_OR_EQUAL': return v <= want;
}
return false;
}
// (GraphQLError: Yoga shows its message to the client; other errors become "Unexpected error.")
const resolvers = {
Query: {
orders(_, { offset, limit, sort, filters }) {
let rows = orders.filter((o) => filters.every((f) => matches(o, f)));
if (sort) {
const dir = sort.descending ? -1 : 1;
rows = [...rows].sort((a, b) => {
const x = value(a, sort.field), y = value(b, sort.field);
return (x < y ? -1 : x > y ? 1 : 0) * dir;
});
}
const size = Math.min(Math.max(limit, 1), 200);
return { rows: rows.slice(Math.max(offset, 0), Math.max(offset, 0) + size), total: rows.length };
}
},
Mutation: {
updateOrder(_, { id, quantity, status }) {
const order = orders.find((o) => o.id === id);
if (!order) throw new GraphQLError(`No order ${id}`);
if (quantity != null) {
if (!Number.isInteger(quantity) || quantity < 1) throw new GraphQLError('The quantity must be a whole number above 0');
order.quantity = quantity;
}
if (status != null) order.status = status;
return order;
}
}
};
const yoga = createYoga({ schema: createSchema({ typeDefs, resolvers }) });
const port = Number(process.env.PORT) || 4000;
createServer(yoga).listen(port, () => console.log(`GraphQL API on http://localhost:${port}/graphql`));
The enums do the checking: a sort or filter on a field the schema does not name, or a condition it does not have, is refused before a resolver runs. The data is generated in memory to keep the example self-contained; a real API asks its database in the resolvers. Errors meant for the user are thrown as GraphQLError, which Yoga passes on; any other error reaches the client as Unexpected error., so a server's internals do not leak. Yoga answers the browser's cross-origin requests, so the app on ng serve's port can call the API on port 4000.
A GraphQL request is a POST with the query and its variables as JSON. The answer has data, and errors when something failed, with the same HTTP status in both cases. This function returns the data or throws the first error:
// A GraphQL request: the query and its variables in, the data or the first error out.
async function graphql<T>(query: string, variables: Record<string, unknown>): Promise<T> {
const response = await fetch(GRAPHQL_URL, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ query, variables })
});
const { data, errors } = (await response.json()) as { data: T; errors?: { message: string }[] };
if (errors?.length) throw new Error(errors[0].message);
return data;
}
It uses fetch rather than Angular's HttpClient. Every request starts inside loadServerData, which works with a Promise (loadOrders(params).then(...), below), and a GraphQL server reports its errors in the body with status 200, so HttpClient's Observables and error handling would add nothing here. HttpClient works too, turned into a Promise with firstValueFrom(this.http.post(...)) (see Data binding for inject(HttpClient)); choose it when your app's interceptors must see the requests, for example to add an Authorization header.
The query asks for the fields the grid shows, and the mutation for the fields it changes:
const ORDERS = /* GraphQL */ `
query Orders($offset: Int!, $limit: Int!, $sort: OrderSort, $filters: [OrderFilter!]) {
orders(offset: $offset, limit: $limit, sort: $sort, filters: $filters) {
total
rows { id customer product quantity price orderDate status }
}
}`;
const UPDATE_ORDER = /* GraphQL */ `
mutation UpdateOrder($id: ID!, $quantity: Int, $status: Status) {
updateOrder(id: $id, quantity: $quantity, status: $status) { id quantity status }
}`;
The grid runs in virtual mode, as in Server-side processing, and the data adapter gets a loadServerData function instead of a URL. It receives the grid's page, sort and filters; variables turns them into the query's arguments, keeping only the fields and conditions the schema has:
// The grid's state as the query's variables
function variables(params: GridState) {
const filters = [];
for (let i = 0; i < Number(params.filterscount || 0); i++) {
const field = params['filterdatafield' + i], condition = params['filtercondition' + i];
if (typeof field === 'string' && fieldNames.has(field) && typeof condition === 'string' && conditions.has(condition)) {
filters.push({ field, condition, value: String(params['filtervalue' + i]) });
}
}
const sort = params.sortdatafield && fieldNames.has(params.sortdatafield) && params.sortorder
? { field: params.sortdatafield, descending: params.sortorder === 'desc' }
: null;
return { offset: params.pagenum * params.pagesize, limit: params.pagesize, sort, filters };
}
export class App {
// …
private createSource() {
const settings = {
datatype: 'json',
id: 'id',
datafields,
// The adapter needs a url to ask for data; loadServerData below does the asking.
url: GRAPHQL_URL,
totalrecords: 0,
// Sorting and filtering happen on the server: ask again.
sort: () => this.grid().updatebounddata('sort'),
filter: () => this.grid().updatebounddata('filter')
};
const adapter = new jqx.dataAdapter(settings, {
// The adapter calls this instead of requesting the url. (A plain function:
// versions before 27.1.0 ignore an async one.)
loadServerData: (params: GridState, _settings: unknown, callback: (page: OrdersPage) => void) => {
this.loadOrders(params).then((page) => {
// (versions before 27.1.0 keep the previous total when the new one is 0: set it here)
adapter.totalrecords = page.totalrecords;
callback(page);
});
}
});
return adapter;
}
// …
}
export class App {
// …
// One page of orders for the grid's state
private async loadOrders(params: GridState): Promise<OrdersPage> {
try {
const { orders } = await graphql<OrdersResult>(ORDERS, variables(params));
this.status.set('');
return { records: orders.rows, totalrecords: orders.total };
} catch (error) {
this.status.set(`Could not load the orders: ${(error as Error).message}`);
return { records: [], totalrecords: 0 };
}
}
// …
}
loadServerData is a plain function that calls the async loadOrders, and it sets adapter.totalrecords itself. Both are for versions before 27.1.0, which ignore an async function there and keep the previous total when a filter matches nothing; they do no harm in 27.1.0. The messages go through the status signal, which is what tells a zoneless app to refresh the text after an answer arrives.
The template is the one of the Supabase tutorial: virtual mode, a filter row, and editing by cell.
<h1>Orders</h1>
<p role="status">{{ status() }}</p>
<jqxGrid #grid
[theme]="'fluent'"
[width]="'100%'"
[height]="560"
[source]="source"
[columns]="columns"
[virtualmode]="true"
[rendergridrows]="rendergridrows"
[pageable]="true"
[pagesize]="20"
[pagesizeoptions]="pagesizeoptions"
[sortable]="true"
[filterable]="true"
[showfilterrow]="true"
[editable]="true"
[selectionmode]="'singlecell'"
(onCellvaluechanged)="cellValueChanged($event)">
</jqxGrid>
A changed cell becomes an updateOrder mutation with the order's id and the one changed field. If the API refuses it, the cell gets its old value back and the page shows the API's message:
export class App {
// …
// An edit is sent as a mutation; if the API refuses it, the cell gets its old value back.
cellValueChanged(event: CellValueChangedEvent): void {
if (!this.applying) {
this.saveEdit(event.args);
}
}
private async saveEdit({ datafield, rowindex, oldvalue, newvalue }: CellValueChangedEvent['args']): Promise<void> {
const grid = this.grid();
const row: Order = grid.getrowdata(rowindex);
try {
await graphql(UPDATE_ORDER, { id: row.id, [datafield]: newvalue });
this.status.set(`Order ${row.id} saved.`);
} catch (error) {
this.status.set(`Order ${row.id} was not saved: ${(error as Error).message}`);
this.applying = true;
grid.setcellvalue(rowindex, datafield, oldvalue);
this.applying = false;
}
}
}
The applying flag keeps the rollback, a change the grid makes itself, from being sent as another mutation.
src/app/app.ts:
import { Component, signal, viewChild } from '@angular/core';
import { jqxGridComponent, jqxGridModule } from 'jqwidgets-ng/jqxgrid';
// The GraphQL endpoint (the server of step 1)
const GRAPHQL_URL = 'http://localhost:4000/graphql';
// A GraphQL request: the query and its variables in, the data or the first error out.
async function graphql<T>(query: string, variables: Record<string, unknown>): Promise<T> {
const response = await fetch(GRAPHQL_URL, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ query, variables })
});
const { data, errors } = (await response.json()) as { data: T; errors?: { message: string }[] };
if (errors?.length) throw new Error(errors[0].message);
return data;
}
const ORDERS = /* GraphQL */ `
query Orders($offset: Int!, $limit: Int!, $sort: OrderSort, $filters: [OrderFilter!]) {
orders(offset: $offset, limit: $limit, sort: $sort, filters: $filters) {
total
rows {
id
customer
product
quantity
price
orderDate
status
}
}
}
`;
const UPDATE_ORDER = /* GraphQL */ `
mutation UpdateOrder($id: ID!, $quantity: Int, $status: Status) {
updateOrder(id: $id, quantity: $quantity, status: $status) {
id
quantity
status
}
}
`;
interface Order {
id: string;
customer: string;
product: string;
quantity: number;
price: number;
orderDate: string;
status: string;
}
interface OrdersResult {
orders: { total: number; rows: Order[] };
}
// The grid's state, as loadServerData receives it: pagenum, pagesize, sortdatafield,
// sortorder, filterscount and filterdatafield0, filtercondition0, filtervalue0 ...
interface GridState {
pagenum: number;
pagesize: number;
sortdatafield?: string;
sortorder?: string;
filterscount?: number;
[filter: string]: unknown;
}
interface OrdersPage {
records: Order[];
totalrecords: number;
}
// A grid event carries its details in event.args.
interface CellValueChangedEvent {
args: { rowindex: number; datafield: string; oldvalue: unknown; newvalue: unknown };
}
const datafields = [
{ name: 'id', type: 'string' },
{ name: 'customer', type: 'string' },
{ name: 'product', type: 'string' },
{ name: 'quantity', type: 'number' },
{ name: 'price', type: 'number' },
{ name: 'orderDate', type: 'date', format: 'yyyy-MM-dd' },
{ name: 'status', type: 'string' }
];
const fieldNames = new Set(datafields.map((f) => f.name));
// the grid's filter conditions that the API's Condition enum has
const conditions = new Set([
'CONTAINS',
'EQUAL',
'NOT_EQUAL',
'GREATER_THAN',
'LESS_THAN',
'GREATER_THAN_OR_EQUAL',
'LESS_THAN_OR_EQUAL'
]);
const statuses = ['New', 'Shipped', 'Delivered', 'Cancelled'];
// The grid's state as the query's variables
function variables(params: GridState) {
const filters = [];
for (let i = 0; i < Number(params.filterscount || 0); i++) {
const field = params['filterdatafield' + i],
condition = params['filtercondition' + i];
if (
typeof field === 'string' &&
fieldNames.has(field) &&
typeof condition === 'string' &&
conditions.has(condition)
) {
filters.push({ field, condition, value: String(params['filtervalue' + i]) });
}
}
const sort =
params.sortdatafield && fieldNames.has(params.sortdatafield) && params.sortorder
? { field: params.sortdatafield, descending: params.sortorder === 'desc' }
: null;
return { offset: params.pagenum * params.pagesize, limit: params.pagesize, sort, filters };
}
@Component({ selector: 'app-root', imports: [jqxGridModule], templateUrl: './app.html' })
export class App {
readonly grid = viewChild.required<jqxGridComponent>('grid');
// What the page tells the user: why something failed, or that an edit was saved.
readonly status = signal('');
readonly source = this.createSource();
readonly columns: jqwidgets.GridColumn[] = [
{ text: 'Order', datafield: 'id', width: 70, filterable: false, editable: false },
{ text: 'Customer', datafield: 'customer', width: 170, editable: false },
{ text: 'Product', datafield: 'product', width: 110, editable: false },
{
text: 'Quantity',
datafield: 'quantity',
width: 90,
cellsalign: 'right',
align: 'right',
filtertype: 'number',
columntype: 'numberinput',
createeditor: (_row, _value, editor) =>
editor.jqxNumberInput({ decimalDigits: 0, min: 1, spinButtons: true }),
validation: (_cell, value) =>
(value !== undefined && Number.isInteger(value) && value > 0) || {
result: false,
message: 'A whole number above 0'
}
},
{
text: 'Price',
datafield: 'price',
width: 90,
cellsalign: 'right',
align: 'right',
cellsformat: 'c2',
filtertype: 'number',
editable: false
},
{
text: 'Date',
datafield: 'orderDate',
width: 110,
cellsformat: 'yyyy-MM-dd',
filtertype: 'range',
editable: false
},
{
text: 'Status',
datafield: 'status',
filtertype: 'list',
filteritems: statuses,
columntype: 'dropdownlist',
createeditor: (_row, _value, editor) =>
editor.jqxDropDownList({ source: statuses, autoDropDownHeight: true })
}
];
readonly pagesizeoptions = ['20', '50', '100'];
// With virtualmode, the grid shows the rows loadServerData handed back for the page.
readonly rendergridrows = (params: { data: unknown[] }) => params.data;
// Set while the grid's cells change from here (a rollback), which is not an edit to save.
private applying = false;
private createSource() {
const settings = {
datatype: 'json',
id: 'id',
datafields,
// The adapter needs a url to ask for data; loadServerData below does the asking.
url: GRAPHQL_URL,
totalrecords: 0,
// Sorting and filtering happen on the server: ask again.
sort: () => this.grid().updatebounddata('sort'),
filter: () => this.grid().updatebounddata('filter')
};
const adapter = new jqx.dataAdapter(settings, {
// The adapter calls this instead of requesting the url. (A plain function:
// versions before 27.1.0 ignore an async one.)
loadServerData: (
params: GridState,
_settings: unknown,
callback: (page: OrdersPage) => void
) => {
this.loadOrders(params).then((page) => {
// (versions before 27.1.0 keep the previous total when the new one is 0: set it here)
adapter.totalrecords = page.totalrecords;
callback(page);
});
}
});
return adapter;
}
// One page of orders for the grid's state
private async loadOrders(params: GridState): Promise<OrdersPage> {
try {
const { orders } = await graphql<OrdersResult>(ORDERS, variables(params));
this.status.set('');
return { records: orders.rows, totalrecords: orders.total };
} catch (error) {
this.status.set(`Could not load the orders: ${(error as Error).message}`);
return { records: [], totalrecords: 0 };
}
}
// An edit is sent as a mutation; if the API refuses it, the cell gets its old value back.
cellValueChanged(event: CellValueChangedEvent): void {
if (!this.applying) {
this.saveEdit(event.args);
}
}
private async saveEdit({
datafield,
rowindex,
oldvalue,
newvalue
}: CellValueChangedEvent['args']): Promise<void> {
const grid = this.grid();
const row: Order = grid.getrowdata(rowindex);
try {
await graphql(UPDATE_ORDER, { id: row.id, [datafield]: newvalue });
this.status.set(`Order ${row.id} saved.`);
} catch (error) {
this.status.set(`Order ${row.id} was not saved: ${(error as Error).message}`);
this.applying = true;
grid.setcellvalue(rowindex, datafield, oldvalue);
this.applying = false;
}
}
}
src/app/app.html:
<h1>Orders</h1>
<p role="status">{{ status() }}</p>
<jqxGrid #grid
[theme]="'fluent'"
[width]="'100%'"
[height]="560"
[source]="source"
[columns]="columns"
[virtualmode]="true"
[rendergridrows]="rendergridrows"
[pageable]="true"
[pagesize]="20"
[pagesizeoptions]="pagesizeoptions"
[sortable]="true"
[filterable]="true"
[showfilterrow]="true"
[editable]="true"
[selectionmode]="'singlecell'"
(onCellvaluechanged)="cellValueChanged($event)">
</jqxGrid>
Start the API with node server.js and the app with ng serve. The pager reads 1-20 of 10000. Sort by Quantity, type ernst in the Customer filter (1-20 of 1250), and pick Shipped in the Status filter. Change a status: the network panel shows one updateOrder mutation. To try the API on its own, open http://localhost:4000/graphql: Yoga serves GraphiQL there.