Angular UI Components Documentation
Supabase gives every project a PostgreSQL database with a REST API, Row Level Security and live change events. This tutorial connects an Angular jqxGrid to a Supabase table with the official JavaScript client, supabase-js: the database pages, sorts and filters 10,000 orders, edits are saved as the user makes them, and changes made anywhere else appear in the grid while it is open.

You need a Supabase project: a free one at supabase.com/dashboard, or a local one with the Supabase CLI (supabase start). Use an Angular CLI app set up as in Angular CLI with jQWidgets, and install supabase-js:
npm install @supabase/supabase-js
Run this SQL in the dashboard's SQL editor (or as a migration). It creates an orders table with 10,000 sample rows, and says what the browser may do with it:
-- The orders table: 10,000 sample orders, and what the browser may do with them.
create table public.orders (
id bigint generated always as identity primary key,
customer text not null,
product text not null,
quantity integer not null check (quantity > 0),
price numeric(10, 2) not null check (price >= 0),
order_date date not null,
status text not null default 'New' check (status in ('New', 'Shipped', 'Delivered', 'Cancelled'))
);
-- 10,000 sample orders
insert into public.orders (customer, product, quantity, price, order_date, status)
select
(array['Alfreds Futterkiste', 'Ana Trujillo', 'Antonio Moreno', 'Around the Horn', 'Berglunds snabbköp',
'Blauer See Delikatessen', 'Bólido Comidas', 'Ernst Handel'])[1 + i % 8],
(array['Chai', 'Chang', 'Aniseed Syrup', 'Tofu', 'Konbu', 'Pavlova', 'Ikura', 'Queso Cabrales',
'Gnocchi', 'Mozzarella'])[1 + (i * 7) % 10],
1 + (i * 13) % 50,
round((5 + (i * 37) % 9500 / 100.0)::numeric, 2),
current_date - (i % 365),
(array['New', 'Shipped', 'Delivered', 'Cancelled'])[1 + (i * 3) % 4]
from generate_series(1, 10000) as i;
-- Row Level Security: the browser uses the anon key, so the table says what that key may do.
-- Here anyone may read orders and change their quantity and status; a real app checks the
-- signed-in user (auth.uid()) in these policies.
alter table public.orders enable row level security;
create policy "Orders are readable" on public.orders
for select to anon, authenticated using (true);
create policy "Orders can be updated" on public.orders
for update to anon, authenticated using (true) with check (true);
grant select on public.orders to anon, authenticated;
grant update (quantity, status) on public.orders to anon, authenticated;
-- Realtime: changes to the table are sent to subscribed browsers (the same as switching on
-- Realtime for the table in the dashboard).
alter publication supabase_realtime add table public.orders;
The browser connects with the project's anon key, which anyone can read in the app's JavaScript. What it may do is decided in the database: Row Level Security is switched on and two policies allow reading and updating, and the column grants allow changing only quantity and status. An update of the price is refused by the database, whatever the app sends. In a real app the policies check the signed-in user, for example using (auth.uid() = owner_id). The last line adds the table to Realtime, for step 5.
The URL and the anon key are under Project Settings > API in the dashboard; supabase start prints them for a local project (the values below are the local ones). The client is made once, when src/app/app.ts loads:
import { createClient } from '@supabase/supabase-js';
import { jqxGridComponent, jqxGridModule } from 'jqwidgets-ng/jqxgrid';
// Your project's URL and anon key: Project Settings > API in the Supabase dashboard
// (these are the ones `supabase start` prints for the local stack).
const SUPABASE_URL = 'http://127.0.0.1:54321';
const SUPABASE_ANON_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0';
const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
In a larger app, keep the URL and key in Angular's environment files and the client in a service with providedIn: 'root', so that every component shares one client.
The grid runs in virtual mode, as in Server-side processing: it asks for one page at a time. Instead of a URL, the data adapter gets a loadServerData function, which receives the grid's state (the page, the sort and the filters) and hands the rows back through a callback. Here it builds one supabase-js query:
range(from, to) asks for the rows of the page, and count: 'exact' for the number of rows that match, which the pager shows;order() sorts by the grid's sort column, or by id so that the pages are stable;// The orders, with the number of rows that match (for the pager)
const selectOrders = () => supabase.from('orders').select('*', { count: 'exact' });
type OrdersQuery = ReturnType<typeof selectOrders>;
// A grid filter as a PostgREST condition. (In a LIKE pattern, % and _ are wildcards:
// the user's text is escaped so that they match themselves.)
function addFilter(query: OrdersQuery, column: unknown, condition: unknown, value: unknown): OrdersQuery {
if (typeof column !== 'string' || !columnNames.has(column)) return query;
const like = String(value).replace(/[\\%_]/g, (c) => '\\' + c);
switch (condition) {
case 'CONTAINS': return query.ilike(column, `%${like}%`);
case 'DOES_NOT_CONTAIN': return query.not(column, 'ilike', `%${like}%`);
case 'STARTS_WITH': return query.ilike(column, `${like}%`);
case 'ENDS_WITH': return query.ilike(column, `%${like}`);
case 'EQUAL': return query.eq(column, value);
case 'NOT_EQUAL': return query.neq(column, value);
case 'GREATER_THAN': return query.gt(column, value);
case 'LESS_THAN': return query.lt(column, value);
case 'GREATER_THAN_OR_EQUAL': return query.gte(column, value);
case 'LESS_THAN_OR_EQUAL': return query.lte(column, value);
case 'NULL': return query.is(column, null);
case 'NOT_NULL': return query.not(column, 'is', null);
default: return query;
}
}
ilike matches without regard to case. In its pattern % and _ are wildcards, so the user's text has them escaped: a search for 50% finds the text 50%. OrdersQuery, the type of the query, comes from selectOrders, so addFilter is typed without naming supabase-js's generic types.
export class App {
// …
// One page of orders for the grid's state
private async loadOrders(params: GridState): Promise<OrdersPage> {
const from = params.pagenum * params.pagesize;
let query = selectOrders().range(from, from + params.pagesize - 1);
for (let i = 0; i < Number(params.filterscount || 0); i++) {
query = addFilter(query, params['filterdatafield' + i], params['filtercondition' + i], params['filtervalue' + i]);
}
const sortBy = params.sortdatafield && columnNames.has(params.sortdatafield) && params.sortorder ? params.sortdatafield : 'id';
query = query.order(sortBy, { ascending: params.sortorder !== 'desc' });
const { data, count, error } = await query;
if (error) {
this.status.set(`Could not load the orders: ${error.message}`);
return { records: [], totalrecords: 0 };
}
this.status.set('');
return { records: data, totalrecords: count ?? 0 };
}
// …
}
The source names the fields and asks again when the user sorts or filters. The adapter calls loadServerData instead of requesting url (it needs one, but nothing is fetched from it):
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: 'orders',
totalrecords: 0,
// Sorting and filtering happen in the database: 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;
}
// …
}
Two details are for versions before 27.1.0 and do no harm in 27.1.0: loadServerData is a plain function that calls the async loadOrders (earlier versions ignore an async function there), and it sets adapter.totalrecords itself, because earlier versions keep the previous total when a filter matches no rows.
The source is a field, made once, and sort, filter and loadServerData are arrow functions, so this is the component. Messages go through the status signal: the answers arrive outside any template event, and with zoneless change detection Angular refreshes the text only because a signal it reads has changed.
The grid itself is the one of the server-side tutorial, with editors for the two columns the database lets the user change:
<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>
export class App {
// …
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: 'order_date', 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 })
}
];
// …
}
When a cell changes, the grid raises cellvaluechanged, which the template binds as (onCellvaluechanged), and the component sends an update of that one column. If the database refuses it, the cell gets its old value back and the page says why, in the words of the database: a quantity of 0 breaks the table's check, for example.
export class App {
// …
// An edit is saved to the database; if the database 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);
const { error } = await supabase.from('orders').update({ [datafield]: newvalue }).eq('id', row.id);
if (error) {
this.status.set(`Order ${row.id} was not saved: ${error.message}`);
this.applying = true;
grid.setcellvalue(rowindex, datafield, oldvalue);
this.applying = false;
} else {
this.status.set(`Order ${row.id} saved.`);
}
}
// …
}
The applying flag keeps the grid's own changes from being saved again: the rollback above, and the live updates of the next step.
A Realtime channel delivers each change to the table. When an order on the current page changes, in another tab, by another user or in the dashboard, its cells show the new values. The channel opens in afterNextRender, once the grid exists, and DestroyRef.onDestroy removes it when the component is destroyed (when the user goes to another route, for example), so no channel is left calling a grid that is gone:
export class App {
// …
constructor() {
const destroyRef = inject(DestroyRef);
// Once the grid exists: changes made elsewhere (another user, another tab, the
// dashboard) arrive through Realtime, and an order on the current page shows its new
// values. The channel is closed with the component.
afterNextRender(() => {
const channel = supabase
.channel('orders-changes')
.on('postgres_changes', { event: 'UPDATE', schema: 'public', table: 'orders' }, ({ new: order }) =>
this.showChange(order as Order)
)
.subscribe();
destroyRef.onDestroy(() => supabase.removeChannel(channel));
});
}
// …
}
export class App {
// …
private showChange(order: Order): void {
const grid = this.grid();
const rows: Order[] = grid.getrows();
const index = rows.findIndex((r) => r.id === order.id);
if (index < 0) return;
this.applying = true;
for (const field of ['quantity', 'status'] as const) {
if (rows[index][field] !== order[field]) grid.setcellvalue(index, field, order[field]);
}
this.applying = false;
}
}
The cells change through setcellvalue, not through the grid's inputs, so the grid keeps its page, sort and filters. Realtime checks the same Row Level Security policies, so a browser only receives the rows it may read. For a page that should also show new and deleted rows, listen to event: '*' and ask for the page again with this.grid().updatebounddata().
src/app/app.ts:
import { afterNextRender, Component, DestroyRef, inject, signal, viewChild } from '@angular/core';
import { createClient } from '@supabase/supabase-js';
import { jqxGridComponent, jqxGridModule } from 'jqwidgets-ng/jqxgrid';
// Your project's URL and anon key: Project Settings > API in the Supabase dashboard
// (these are the ones `supabase start` prints for the local stack).
const SUPABASE_URL = 'http://127.0.0.1:54321';
const SUPABASE_ANON_KEY =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0';
const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
interface Order {
id: number;
customer: string;
product: string;
quantity: number;
price: number;
order_date: string;
status: string;
}
// 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: 'number' },
{ name: 'customer', type: 'string' },
{ name: 'product', type: 'string' },
{ name: 'quantity', type: 'number' },
{ name: 'price', type: 'number' },
{ name: 'order_date', type: 'date', format: 'yyyy-MM-dd' },
{ name: 'status', type: 'string' }
];
const columnNames = new Set(datafields.map((f) => f.name));
const statuses = ['New', 'Shipped', 'Delivered', 'Cancelled'];
// The orders, with the number of rows that match (for the pager)
const selectOrders = () => supabase.from('orders').select('*', { count: 'exact' });
type OrdersQuery = ReturnType<typeof selectOrders>;
// A grid filter as a PostgREST condition. (In a LIKE pattern, % and _ are wildcards:
// the user's text is escaped so that they match themselves.)
function addFilter(
query: OrdersQuery,
column: unknown,
condition: unknown,
value: unknown
): OrdersQuery {
if (typeof column !== 'string' || !columnNames.has(column)) return query;
const like = String(value).replace(/[\\%_]/g, (c) => '\\' + c);
switch (condition) {
case 'CONTAINS':
return query.ilike(column, `%${like}%`);
case 'DOES_NOT_CONTAIN':
return query.not(column, 'ilike', `%${like}%`);
case 'STARTS_WITH':
return query.ilike(column, `${like}%`);
case 'ENDS_WITH':
return query.ilike(column, `%${like}`);
case 'EQUAL':
return query.eq(column, value);
case 'NOT_EQUAL':
return query.neq(column, value);
case 'GREATER_THAN':
return query.gt(column, value);
case 'LESS_THAN':
return query.lt(column, value);
case 'GREATER_THAN_OR_EQUAL':
return query.gte(column, value);
case 'LESS_THAN_OR_EQUAL':
return query.lte(column, value);
case 'NULL':
return query.is(column, null);
case 'NOT_NULL':
return query.not(column, 'is', null);
default:
return query;
}
}
@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: 'order_date',
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, a live update), which are not
// edits to save.
private applying = false;
constructor() {
const destroyRef = inject(DestroyRef);
// Once the grid exists: changes made elsewhere (another user, another tab, the
// dashboard) arrive through Realtime, and an order on the current page shows its new
// values. The channel is closed with the component.
afterNextRender(() => {
const channel = supabase
.channel('orders-changes')
.on(
'postgres_changes',
{ event: 'UPDATE', schema: 'public', table: 'orders' },
({ new: order }: any) => this.showChange(order as Order)
)
.subscribe();
destroyRef.onDestroy(() => supabase.removeChannel(channel));
});
}
private createSource() {
const settings = {
datatype: 'json',
id: 'id',
datafields,
// The adapter needs a url to ask for data; loadServerData below does the asking.
url: 'orders',
totalrecords: 0,
// Sorting and filtering happen in the database: 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> {
const from = params.pagenum * params.pagesize;
let query = selectOrders().range(from, from + params.pagesize - 1);
for (let i = 0; i < Number(params.filterscount || 0); i++) {
query = addFilter(
query,
params['filterdatafield' + i],
params['filtercondition' + i],
params['filtervalue' + i]
);
}
const sortBy =
params.sortdatafield && columnNames.has(params.sortdatafield) && params.sortorder
? params.sortdatafield
: 'id';
query = query.order(sortBy, { ascending: params.sortorder !== 'desc' });
const { data, count, error } = await query;
if (error) {
this.status.set(`Could not load the orders: ${error.message}`);
return { records: [], totalrecords: 0 };
}
this.status.set('');
return { records: data, totalrecords: count ?? 0 };
}
// An edit is saved to the database; if the database 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);
const { error } = await supabase
.from('orders')
.update({ [datafield]: newvalue })
.eq('id', row.id);
if (error) {
this.status.set(`Order ${row.id} was not saved: ${error.message}`);
this.applying = true;
grid.setcellvalue(rowindex, datafield, oldvalue);
this.applying = false;
} else {
this.status.set(`Order ${row.id} saved.`);
}
}
private showChange(order: Order): void {
const grid = this.grid();
const rows: Order[] = grid.getrows();
const index = rows.findIndex((r) => r.id === order.id);
if (index < 0) return;
this.applying = true;
for (const field of ['quantity', 'status'] as const) {
if (rows[index][field] !== order[field]) grid.setcellvalue(index, field, order[field]);
}
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>
Run ng serve and open the app. The pager reads 1-20 of 10000. Click the Quantity header twice to sort from the largest order, and type ernst in the Customer filter: the pager reads 1-20 of 1250, still sorted. Type a name that no order has: the grid is empty and the pager reads 0-0 of 0. Double-click a status, pick Delivered, and see the row change in the Table Editor of the dashboard. Open the app in a second tab and change a quantity in the first: the second tab shows it a moment later.