Documentation
Supabase gives every project a PostgreSQL database with a REST API, Row Level Security and live change events. This tutorial connects a 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). The page is a plain HTML file that loads jQWidgets and supabase-js from CDNs, as in Bind the jQuery Grid to data; serve it from any web server, such as npx serve.
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 page's source. 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 page 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.
supabase-js is an ES module, so the page's script is <script type="module">. 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).
import { createClient } from 'https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2/+esm';
// 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);
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;// 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, column, condition, value) {
if (!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%.
// One page of orders for the grid's state. params holds pagenum, pagesize,
// sortdatafield, sortorder, filterscount and filterdatafield0, filtercondition0,
// filtervalue0 ...
async function loadOrders(params) {
const from = params.pagenum * params.pagesize;
let query = supabase
.from('orders')
.select('*', { count: 'exact' })
.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 = 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) {
status.textContent = `Could not load the orders: ${error.message}`;
return { records: [], totalrecords: 0 };
}
status.textContent = '';
return { records: data, totalrecords: count };
}
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):
const source = {
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: () => grid.jqxGrid('updatebounddata', 'sort'),
filter: () => grid.jqxGrid('updatebounddata', 'filter')
};
// One page of orders for the grid's state. params holds pagenum, pagesize,
// sortdatafield, sortorder, filterscount and filterdatafield0, filtercondition0,
// filtervalue0 ...
async function loadOrders(params) {
const from = params.pagenum * params.pagesize;
let query = supabase
.from('orders')
.select('*', { count: 'exact' })
.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 = 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) {
status.textContent = `Could not load the orders: ${error.message}`;
return { records: [], totalrecords: 0 };
}
status.textContent = '';
return { records: data, totalrecords: count };
}
const adapter = new $.jqx.dataAdapter(source, {
// The adapter calls this instead of requesting the url. (A plain function:
// versions before 27.1.0 ignore an async one.)
loadServerData: (params, settings, callback) => {
loadOrders(params).then((result) => {
// (versions before 27.1.0 keep the previous total when the new one is 0: set it here)
adapter.totalrecords = result.totalrecords;
callback(result);
});
}
});
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 grid itself is the one of the server-side tutorial, with editors for the two columns the database lets the user change:
grid.jqxGrid({
theme: 'fluent',
width: '100%',
height: 560,
source: adapter,
virtualmode: true,
rendergridrows: (params) => params.data,
pageable: true,
pagesize: 20,
pagesizeoptions: ['20', '50', '100'],
sortable: true,
filterable: true,
showfilterrow: true,
editable: true,
selectionmode: 'singlecell',
columns: [
{ 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) => (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: ['New', 'Shipped', 'Delivered', 'Cancelled'],
columntype: 'dropdownlist',
createeditor: (row, value, editor) => editor.jqxDropDownList({ source: ['New', 'Shipped', 'Delivered', 'Cancelled'], autoDropDownHeight: true })
}
]
});
When a cell changes, cellvaluechanged 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.
// An edit is saved to the database; if the database refuses it, the cell gets its old value back.
let applying = false;
async function saveEdit({ datafield, rowindex, oldvalue, newvalue }) {
const row = grid.jqxGrid('getrowdata', rowindex);
const { error } = await supabase.from('orders').update({ [datafield]: newvalue }).eq('id', row.id);
if (error) {
status.textContent = `Order ${row.id} was not saved: ${error.message}`;
applying = true;
grid.jqxGrid('setcellvalue', rowindex, datafield, oldvalue);
applying = false;
} else {
status.textContent = `Order ${row.id} saved.`;
}
}
grid.on('cellvaluechanged', (event) => {
if (!applying) saveEdit(event.args);
});
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:
// Changes made elsewhere (another user, another tab, the dashboard) arrive through
// Realtime; an order on the current page shows its new values.
supabase
.channel('orders-changes')
.on('postgres_changes', { event: 'UPDATE', schema: 'public', table: 'orders' }, ({ new: order }) => {
const rows = grid.jqxGrid('getrows');
const index = rows.findIndex((r) => r.id === order.id);
if (index < 0) return;
applying = true;
for (const field of ['quantity', 'status']) {
if (rows[index][field] !== order[field]) grid.jqxGrid('setcellvalue', index, field, order[field]);
}
applying = false;
})
.subscribe();
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 grid.jqxGrid('updatebounddata').
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Orders from Supabase</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/styles/jqx.base.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/styles/jqx.fluent.css">
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxcore.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxdata.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxbuttons.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxscrollbar.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxmenu.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxlistbox.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxdropdownlist.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxcalendar.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxdatetimeinput.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxnumberinput.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.selection.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.edit.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.sort.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.filter.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxgrid.pager.js"></script>
</head>
<body>
<main style="padding: 16px;">
<h1>Orders</h1>
<p id="status" role="status"></p>
<div id="grid"></div>
</main>
<script type="module">
import { createClient } from 'https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2/+esm';
// 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);
const grid = $('#grid');
const status = document.getElementById('status');
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));
// 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, column, condition, value) {
if (!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;
}
}
const source = {
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: () => grid.jqxGrid('updatebounddata', 'sort'),
filter: () => grid.jqxGrid('updatebounddata', 'filter')
};
// One page of orders for the grid's state. params holds pagenum, pagesize,
// sortdatafield, sortorder, filterscount and filterdatafield0, filtercondition0,
// filtervalue0 ...
async function loadOrders(params) {
const from = params.pagenum * params.pagesize;
let query = supabase
.from('orders')
.select('*', { count: 'exact' })
.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 = 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) {
status.textContent = `Could not load the orders: ${error.message}`;
return { records: [], totalrecords: 0 };
}
status.textContent = '';
return { records: data, totalrecords: count };
}
const adapter = new $.jqx.dataAdapter(source, {
// The adapter calls this instead of requesting the url. (A plain function:
// versions before 27.1.0 ignore an async one.)
loadServerData: (params, settings, callback) => {
loadOrders(params).then((result) => {
// (versions before 27.1.0 keep the previous total when the new one is 0: set it here)
adapter.totalrecords = result.totalrecords;
callback(result);
});
}
});
grid.jqxGrid({
theme: 'fluent',
width: '100%',
height: 560,
source: adapter,
virtualmode: true,
rendergridrows: (params) => params.data,
pageable: true,
pagesize: 20,
pagesizeoptions: ['20', '50', '100'],
sortable: true,
filterable: true,
showfilterrow: true,
editable: true,
selectionmode: 'singlecell',
columns: [
{ 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) => (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: ['New', 'Shipped', 'Delivered', 'Cancelled'],
columntype: 'dropdownlist',
createeditor: (row, value, editor) => editor.jqxDropDownList({ source: ['New', 'Shipped', 'Delivered', 'Cancelled'], autoDropDownHeight: true })
}
]
});
// An edit is saved to the database; if the database refuses it, the cell gets its old value back.
let applying = false;
async function saveEdit({ datafield, rowindex, oldvalue, newvalue }) {
const row = grid.jqxGrid('getrowdata', rowindex);
const { error } = await supabase.from('orders').update({ [datafield]: newvalue }).eq('id', row.id);
if (error) {
status.textContent = `Order ${row.id} was not saved: ${error.message}`;
applying = true;
grid.jqxGrid('setcellvalue', rowindex, datafield, oldvalue);
applying = false;
} else {
status.textContent = `Order ${row.id} saved.`;
}
}
grid.on('cellvaluechanged', (event) => {
if (!applying) saveEdit(event.args);
});
// Changes made elsewhere (another user, another tab, the dashboard) arrive through
// Realtime; an order on the current page shows its new values.
supabase
.channel('orders-changes')
.on('postgres_changes', { event: 'UPDATE', schema: 'public', table: 'orders' }, ({ new: order }) => {
const rows = grid.jqxGrid('getrows');
const index = rows.findIndex((r) => r.id === order.id);
if (index < 0) return;
applying = true;
for (const field of ['quantity', 'status']) {
if (rows[index][field] !== order[field]) grid.jqxGrid('setcellvalue', index, field, order[field]);
}
applying = false;
})
.subscribe();
</script>
</body>
</html>
Open the page. 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 page in a second tab and change a quantity in the first: the second tab shows it a moment later.