components
On this page
Component reference

The table component

A table with optional filtering and sorting. Unlike most others, this component does not have a fixed set of item properties, any property that is used will be rendered directly as a column in the table. Tables can contain rich text, including images, links, and icons. Table rows can be styled with a background color, and the table can be made striped, hoverable, and bordered.

Advanced users can apply custom styles to table columns using a CSS class with the same name as the column, and to table rows using the _sqlpage_css_class property.

Top-level parameters

Set these in the SELECT that names the component.

align_center TEXT

Name of a column the contents of which should be center-aligned. This argument can be repeated multiple times to align multiple columns to the center.

align_right TEXT

Name of a column the contents of which should be right-aligned. This argument can be repeated multiple times to align multiple columns to the right. Introduced in v0.15.0.

border BOOLEAN

Whether to draw borders on all sides of the table and cells.

class TEXT

class attribute added to the container in HTML. It can be used to apply custom styling to this item through css. Added in v0.18.0.

currency TEXT

The ISO 4217 currency code (e.g., USD, EUR, GBP, etc.) to use when formatting monetary values.

custom_actions JSON

If set, a column of custom action buttons will be added to each row. The value of this property should be a JSON array of objects, each object defining a button with the following properties: name (the text to display on the button), icon (the tabler icon name or image link to display on the button), link (the URL to navigate to when the button is clicked, possibly containing the {id} placeholder that will be replaced by the value of the _sqlpage_id property for that row), and tooltip (optional text to display when hovering over the button). Added in v0.39.0

delete_url TEXT

If set, a delete button will be added to each row. The value of this property should be a URL, possibly containing the {id} placeholder that will be replaced by the value of the _sqlpage_id property for that row. Clicking the delete button will take the user to that URL. Added in v0.39.0

description TEXT

Description of the table contents. Helps users with screen readers to find a table and understand what it’s about.

edit_url TEXT

If set, an edit button will be added to each row. The value of this property should be a URL, possibly containing the {id} placeholder that will be replaced by the value of the _sqlpage_id property for that row. Clicking the edit button will take the user to that URL. Added in v0.39.0

embed TEXT

Name of a column whose values are URLs to HTML fragments, such as other SQLPage pages. Repeat this property to select multiple columns. The browser fetches each nonempty URL with _sqlpage_embed=1, which skips the SQLPage shell, and initializes any components inside the cell. Use only URLs whose HTML you trust. There is one request per populated cell. Sorting uses the original URL, and search skips embedded cells.

empty_description TEXT

Text to display if the table does not contain any row. Defaults to "no data".

freeze_columns BOOLEAN

Whether to freeze the leftmost column of the table.

freeze_footers BOOLEAN

Whether to freeze the footer (bottom row) of the table, only works if that row has the _sqlpage_footer property applied to it.

freeze_headers BOOLEAN

Whether to freeze the top row of the table.

hover BOOLEAN

Whether to enable a hover state on table rows.

icon TEXT

Set this to the name of a column whose content should be interpreted as a tabler icon name. Used to display icons in the table. This argument can be repeated multiple times to intepret multiple columns as icons. Introduced in v0.8.0.

id TEXT

id attribute added to the container in HTML. It can be used to target this item through css or for scrolling to this item through links (use "#id" in link url).

initial_search_value TEXT

Pre-fills the search bar used to filter the table. The user will still be able to edit the value to display table rows that will initially be filtered out.

markdown TEXT

Set this to the name of a column whose content should be interpreted as markdown . Used to display rich text with links in the table. This argument can be repeated multiple times to intepret multiple columns as markdown.

money TEXT

Name of a numeric column whose values should be displayed as currency amounts, in the currency defined by the currency property. This argument can be repeated multiple times.

monospace TEXT

Name of a column the contents of which should be displayed in monospace. This argument can be repeated multiple times to display multiple columns in monospace. Introduced in v0.32.1.

number_format_digits INTEGER

Maximum number of decimal digits to display for numeric values.

number_format_locale TEXT

A BCP 47 language tag (e.g. "de-DE", "en-IN") deciding how numbers and monetary values are formatted. Defaults to the locale of the visitor's browser.

overflow BOOLEAN

Whether to to let "wide" tables overflow across the right border and enable browser-based horizontal scrolling.

raw_numbers TEXT

Name of a column whose values are numeric, but should be displayed as raw numbers without any formatting (no thousands separators, decimal separator is always a dot). This argument can be repeated multiple times.

search_placeholder TEXT

Customizes the placeholder text shown in the search input field. Replaces the default "Search..." with text that better describes what users should search for.

small BOOLEAN

Whether to use compact table.

sort BOOLEAN

Make the columns clickable to let the user sort by the value contained in the column.

striped_columns BOOLEAN

Whether to add zebra-striping to any table column.

striped_rows BOOLEAN

Whether to add zebra-striping to any table row.

title TEXT

A title displayed above the table.

Row-level parameters

Return these columns in the rows that follow the component.

_sqlpage_actions JSON

Sets custom action buttons for this specific row in addition to any defined at the table level, The value of this property should be a JSON array of objects, each object defining a button with the following properties: name (the text to display on the button), icon (the tabler icon name or image link to display on the button), link (the URL to navigate to when the button is clicked, possibly containing the {id} placeholder that will be replaced by the value of the _sqlpage_id property for that row), and tooltip (optional text to display when hovering over the button). Added in v0.39.0

_sqlpage_color COLOR

Sets the background color of the row. Added in v0.8.0.

_sqlpage_css_class TEXT

For advanced users. Sets a css class on the table row. Added in v0.8.0.

_sqlpage_id TEXT

Sets the id of the html tabler row element. Allows you to make links targeting a specific row in a table.

Examples

The most basic table.

index.sql
select
    'table' as "component";

select
    1 as "a",
    2 as "b";

select
    3 as "a",
    4 as "b";

Result

a b
1 2
3 4

A table of users with filtering and sorting.

index.sql
select
    'table' as "component",
    TRUE as "sort",
    TRUE as "search",
    'Filter by name' as "search_placeholder";

select
    'Ophir' as "First Name",
    'Lojkine' as "Last Name",
    'lovasoa' as "Pseudonym";

select
    'Linus' as "First Name",
    'Torvalds' as "Last Name",
    'torvalds' as "Pseudonym";

Result

Ophir Lojkine lovasoa
Linus Torvalds torvalds

A table that uses markdown to display links

index.sql
select
    'table' as "component",
    'Name' as "markdown",
    'icon' as "icon",
    TRUE as "search";

select
    'table' as "icon",
    '[Table](?component=table)' as "name",
    'Displays SQL results as a searchable table.' as "description",
    'red' as "_sqlpage_color";

select
    'timeline' as "icon",
    '[Chart](?component=chart)' as "name",
    'Show graphs based on numeric data.' as "description";

Result

icon name description

Table

Displays SQL results as a searchable table.

Chart

Show graphs based on numeric data.

Example 4

embed: Chart names the column to render. Each row supplies its own chart URL in Chart; an empty value leaves that cell empty. The browser requests each populated cell separately.

index.sql
select
    'table' as "component",
    'Chart' as "embed";

select
    7 as "Starting number",
    '/examples/chart.sql?n=7&color=blue' as "Chart";

select
    13 as "Starting number",
    '/examples/chart.sql?n=13&color=green' as "Chart";

Result

Starting number Chart
7
Loading...
13
Loading...

A sortable table with a colored footer showing the average value of its entries.

index.sql
select
    'table' as "component",
    TRUE as "sort";

select
    'Rudolph Lingens' as "Person",
    190 as "Height";

select
    'Jane Doe' as "Person",
    150 as "Height";

select
    'John Doe' as "Person",
    200 as "Height";

select
    TRUE as "_sqlpage_footer",
    'green' as "_sqlpage_color",
    'Average' as "Person",
    180 as "Height";

Result

Rudolph Lingens 190
Jane Doe 150
John Doe 200
Average 180

Example 6

A table with column sorting. Sorting sorts numbers in numeric order, and strings in alphabetical order.

Numbers can be displayed

  • as raw digits without formatting using the raw_numbers property,
  • as currency using the money property to define columns that contain monetary values and currency to define the currency,
  • as numbers with a fixed maximum number of decimal digits using the number_format_digits property.
index.sql
select
    'table' as "component",
    TRUE as "sort",
    'Price' as "align_right",
    'Amount in stock' as "align_right",
    JSON('["part_no"]') as "align_center",
    JSON('["id"]') as "raw_numbers",
    'USD' as "currency",
    JSON('["Price"]') as "money";

select
    31456 as "id",
    'SQL-TABLE-856-G' as "part_no",
    12 as "Price",
    5 as "Amount in stock";

select
    996 as "id",
    'SQL-FORMS-86-M' as "part_no",
    1 as "Price",
    1234 as "Amount in stock";

select
    131456 as "id",
    'SQL-CARDS-56-K' as "part_no",
    127 as "Price",
    98 as "Amount in stock";

Result

31456 SQL-TABLE-856-G 12 5
996 SQL-FORMS-86-M 1 1234
131456 SQL-CARDS-56-K 127 98

A table with some presentation options

index.sql
select
    'table' as "component",
    TRUE as "hover",
    TRUE as "striped_rows",
    'Some Star Trek Starfleet starships' as "description",
    TRUE as "small",
    'NCC-' as "initial_search_value";

select
    'USS Enterprise' as "name",
    'NCC-1701-C' as "registry",
    'Ambassador' as "class";

select
    'USS Archer' as "name",
    'NCC-44278' as "registry",
    'Archer' as "class";

select
    'USS Endeavour' as "name",
    'NCC-06' as "registry",
    'Columbia' as "class";

select
    'USS Constellation' as "name",
    'NCC-1974' as "registry",
    'Constellation' as "class";

select
    'USS Dakota' as "name",
    'NCC-63892' as "registry",
    'Akira' as "class";

select
    'USS Defiant' as "name",
    'IX-74205' as "registry",
    'Defiant' as "class";

Result

Some Star Trek Starfleet starships
name registry class
USS Enterprise NCC-1701-C Ambassador
USS Archer NCC-44278 Archer
USS Endeavour NCC-06 Columbia
USS Constellation NCC-1974 Constellation
USS Dakota NCC-63892 Akira
USS Defiant IX-74205 Defiant

An empty table with a friendly message

index.sql
select
    'table' as "component",
    'Nothing to see here at the moment.' as "empty_description";

Result

Nothing to see here at the moment.

Example 9

freeze_columns keeps the first column visible when scrolling sideways. freeze_headers keeps the column names visible when scrolling down. The footer in this example scrolls normally; set freeze_footers to pin it too.

index.sql
select
    'table' as "component",
    TRUE as "freeze_columns",
    TRUE as "freeze_headers";

select
    'SQL Execution' as "feature",
    'Fully compatible with existing databases SQL dialects, executes any SQL query.' as "description",
    'Short learning curve, easy to use, interoperable with existing tools.' as "benefits";

select
    'Data Visualization' as "feature",
    'Automatic visualizations of query results: graphs, plots, pie charts, heatmaps, etc.' as "description",
    'Quickly analyze data trends, attractive and easy to understand, no external visualization tools or languages to learn.' as "benefits";

select
    'User Authentication' as "feature",
    'Supports user sessions, from basic auth to single sign-on.' as "description",
    'Secure, enforces access control policies, and provides a customizable security layer.' as "benefits";

select
    'APIs' as "feature",
    'Allows building JSON REST APIs and integrating with external APIs.' as "description",
    'Enables automation and integration with other platforms, facilitates data exchange.' as "benefits";

select
    'Files' as "feature",
    'File uploads, downloads and processing. Supports local filesystem and database storage.' as "description",
    'Convenient file management, secure data handling, flexible storage options, integrates with existing systems.' as "benefits";

select
    'Maps' as "feature",
    'Supports GeoJSON and is compatible with GIS data for map visualization.' as "description",
    'Geospatial data representation, integrates with geographic information systems.' as "benefits";

select
    'Custom Components' as "feature",
    'Build advanced features using HTML, JavaScript, and CSS.' as "description",
    'Tailor-made user experiences, easy to implement custom UI requirements.' as "benefits";

select
    'Forms' as "feature",
    'Insert and update data in databases based on user input.' as "description",
    'Simplified data input and management, efficient user interactions with databases.' as "benefits";

select
    'DB Compatibility' as "feature",
    'Works with MySQL, PostgreSQL, SQLite, Microsoft SQL Server and compatible databases.' as "description",
    'Broad compatibility with popular database systems, ensures seamless integration.' as "benefits";

select
    'Security' as "feature",
    'Built-in protection against common web vulnerabilities: no SQL injection, no XSS.' as "description",
    'Passes audits and security reviews, reduces the risk of data breaches.' as "benefits";

select
    'Performance' as "feature",
    'Designed for performance, with a focus on efficient data processing and minimal overhead.' as "description",
    'Quickly processes large datasets, handles high volumes of requests, and minimizes server load.' as "benefits";

select
    TRUE as "_sqlpage_footer",
    'Summary' as "feature",
    'Summarizes the features of the product.' as "description",
    'Provides a quick overview of the product''s features and benefits.' as "benefits";

Result

feature description benefits
SQL Execution Fully compatible with existing databases SQL dialects, executes any SQL query. Short learning curve, easy to use, interoperable with existing tools.
Data Visualization Automatic visualizations of query results: graphs, plots, pie charts, heatmaps, etc. Quickly analyze data trends, attractive and easy to understand, no external visualization tools or languages to learn.
User Authentication Supports user sessions, from basic auth to single sign-on. Secure, enforces access control policies, and provides a customizable security layer.
APIs Allows building JSON REST APIs and integrating with external APIs. Enables automation and integration with other platforms, facilitates data exchange.
Files File uploads, downloads and processing. Supports local filesystem and database storage. Convenient file management, secure data handling, flexible storage options, integrates with existing systems.
Maps Supports GeoJSON and is compatible with GIS data for map visualization. Geospatial data representation, integrates with geographic information systems.
Custom Components Build advanced features using HTML, JavaScript, and CSS. Tailor-made user experiences, easy to implement custom UI requirements.
Forms Insert and update data in databases based on user input. Simplified data input and management, efficient user interactions with databases.
DB Compatibility Works with MySQL, PostgreSQL, SQLite, Microsoft SQL Server and compatible databases. Broad compatibility with popular database systems, ensures seamless integration.
Security Built-in protection against common web vulnerabilities: no SQL injection, no XSS. Passes audits and security reviews, reduces the risk of data breaches.
Performance Designed for performance, with a focus on efficient data processing and minimal overhead. Quickly processes large datasets, handles high volumes of requests, and minimizes server load.
Summary Summarizes the features of the product. Provides a quick overview of the product's features and benefits.

Example 10

Dynamic column names in a table

In all the previous examples, the column names were hardcoded in the SQL query. This makes it very easy to quickly visualize the results of a query as a table, but it can be limiting if you want to include columns that are not known in advance. In situations when the number and names of the columns depend on the data, or on variables, you can use the dynamic component to generate the table columns dynamically.

For that, you will need to return JSON objects from your SQL query, where the keys are the column names, and the values are the cell contents.

Databases offer utilities to generate JSON objects from query results

  • In PostgreSQL, you can use the json_build_object function for a fixed number of columns, or json_object_agg for a dynamic number of columns.
  • In SQLite, you can use the json_object function for a fixed number of columns, or the json_group_object function for a dynamic number of columns.
  • In MySQL, you can use the JSON_OBJECT function for a fixed number of columns, or the JSON_OBJECTAGG function for a dynamic number of columns.
  • In Microsoft SQL Server, you can use the FOR JSON PATH clause.

For instance, let's say we have a table with three columns: store, item, and quantity_sold. We want to create a pivot table where each row is a store, and each column is an item. We will return a set of json objects that look like this: {"store":"Madrid", "Item1": 42, "Item2": 7, "Item3": 0}

SELECT 'table' AS component;
with filled_data as (
  select
    stores.store, items.item,
    (select coalesce(sum(quantity_sold), 0) from store_sales where store=stores.store and item=items.item) as quantity 
  from (select distinct store from store_sales) as stores
  cross join (select distinct item from store_sales) as items
  order by stores.store, items.item
)
SELECT 
    'dynamic' AS component,
    JSON_PATCH( -- SQLite-specific, refer to your database documentation for the equivalent JSON functions
        JSON_OBJECT('store', store),
        JSON_GROUP_OBJECT(item, quantity)
    ) AS properties
FROM 
    filled_data
GROUP BY 
    store;

This will generate a table with the stores in the first column, and the items in the following columns, with the quantity sold in each store for each item.

Example 11

Using Action Buttons in a table.

Preset Actions: edit_url & delete_url

Since edit and delete are common actions, the table component has dedicated edit_url and delete_url properties to add buttons for these actions. The value of these properties should be a URL, containing the {id} placeholder that will be replaced by the value of the _sqlpage_id property for that row.

Column with fixed action buttons

You may want to add custom action buttons to your table rows, for instance to view details, download a file, or perform a custom operation. For this, the table component has a custom_actions top-level property that lets you define a column of buttons, each button defined by a name, an icon, a link, and an optional tooltip.

Column with variable action buttons

The table component also supports the row level _sqlpage_actions column in your data table. This is helpful if you want a more complex logic, for instance to disable a button on some rows, or to change the link or icon based on the row data.

WARNING! If the number of array items in _sqlpage_actions is not consistent across all rows, the table may not render correctly. You can leave blank spaces by including an object with only the name property.

The table has a column of buttons, each button defined by the custom_actions column at the table level, and by the _sqlpage_actions property at the row level.

custom_actions & _sqlpage_actions JSON properties.

Each button is defined by the following properties:

  • name: sets the column header and the tooltip if no tooltip is provided,
  • tooltip: text to display when hovering over the button,
  • link: the URL to navigate to when the button is clicked, possibly containing the {id} placeholder that will be replaced by the value of the _sqlpage_id property for that row,
  • icon: the tabler icon name or image link to display on the button

Example using all of the above

index.sql
select
    'table' as "component",
    '/examples/show_variables.sql?action=edit&update_id={id}' as "edit_url",
    '/examples/show_variables.sql?action=delete&delete_id={id}' as "delete_url",
    JSON('{"name":"history","tooltip":"View Standard History","link":"/examples/show_variables.sql?action=history&standard_id={id}","icon":"history"}') as "custom_actions";

select
    'CalStd' as "name",
    'PharmaCo' as "vendor",
    'P1234' as "Product",
    'T23523' as "lot number",
    'Available' as "status",
    '2026-10-13' as "expires on",
    32 as "_sqlpage_id",
    JSON('{"name":"View PDF","tooltip":"View Presentation","link":"https://sql-page.com/pgconf/2024-sqlpage-badass.pdf","icon":"file-type-pdf"}') as "_sqlpage_actions",
    JSON('{"name":"Action","tooltip":"Set In Use","link":"/examples/show_variables.sql?action=set_in_use&standard_id=32","icon":"caret-right"}') as "_sqlpage_actions";

select
    'CalStd' as "name",
    'PharmaCo' as "vendor",
    'P1234' as "Product",
    'T2352' as "lot number",
    'In Use' as "status",
    '2026-10-14' as "expires on",
    33 as "_sqlpage_id",
    JSON('{"name":"View PDF","tooltip":"View Presentation","link":"https://sql-page.com/pgconf/2024-sqlpage-badass.pdf","icon":"file-type-pdf"}') as "_sqlpage_actions",
    JSON('{"name":"Action","tooltip":"Retire Standard","link":"/examples/show_variables.sql?action=retire&standard_id=33","icon":"test-pipe-off"}') as "_sqlpage_actions";

select
    'CalStd' as "name",
    'PharmaCo' as "vendor",
    'P1234' as "Product",
    'A123' as "lot number",
    'Discarded' as "status",
    '2026-09-30' as "expires on",
    31 as "_sqlpage_id",
    JSON('{"name":"View PDF","tooltip":"View Presentation","link":"https://sql-page.com/pgconf/2024-sqlpage-badass.pdf","icon":"file-type-pdf"}') as "_sqlpage_actions",
    JSON('{"name":"Action"}') as "_sqlpage_actions";

Result

name vendor Product lot number status expires on Edit Delete history View PDF Action
CalStd PharmaCo P1234 T23523 Available 2026-10-13
CalStd PharmaCo P1234 T2352 In Use 2026-10-14
CalStd PharmaCo P1234 A123 Discarded 2026-09-30