Skip to main content

Basic API table

The table asks the API for one page at a time: GET url?page=&limit=&search=&filters[key]=&sorts[key]=asc|desc, and reads the Starkit contract answer. fields lists the columns; a format function returns the cell content (HTML, so user data in it goes through Starkit.escapeHtml). Click a sortable title to sort by that column (ascending, descending, none); Shift + click adds the column to the sort, so the products endpoint sorts by several columns. The filter row is ordinary form controls named filters[key]: the table listens to their input and change events, so no binding is needed. The View menu shows or hides columns and sets the density at once. The SKU and the actions stay in place while the table scrolls sideways. Select rows and click Delete: the table sends table-bulk with the action and the selected keys, this example shows a toast and sends table-reload.

New product

selected

Products
DescriptionActions
Loading…
Loading more…

Could not load the data. Check your connection and try again.

No results

Simple pagination

For a server with a simple or cursor paginator: it knows the page and whether there is a next one, and nothing more. The default slot adds a header row above the column titles (Product, Availability), whose cells follow the order of fields. This parse returns no lastPage and no total, so the pagination shows Previous, the page, and Next, and the status has no total. The table is compact and bordered.

New product

selected

Products, simple pagination
Product Availability
DescriptionActions
Loading…
Loading more…

Could not load the data. Check your connection and try again.

No results

Infinite scroll

With infinite, the next page is appended when the scroll reaches the end of the table, with a Loading more… row meanwhile. The Load more button is always there too: keyboard users reach it without scrolling, and it fills a table too short to scroll. A new search, filter, or sort empties the list and starts again from page 1. limit-options sets the rows per page choices; the first one is the starting value. The header and the footer (the foot slot) stay in view while the list scrolls (sticky-header, sticky-footer).

New product

selected

Products, infinite scroll
DescriptionActions
Loading…
Loading more…

Could not load the data. Check your connection and try again.

No results

Prices exclude tax. Scroll to the end of the list to load the next page.

Adapting to your server

The table sends the standard request and reads the standard answer; config changes only what your server does differently. This table talks to a Laravel paginator. params(state) turns { page, limit, search, filters, sorts } into that server's query string, parse(response) says where the rows and the page info are, map(row) changes each row, format formats cells by column key (here the description is shortened), and headers (an object, or a function called on every request) is where a token goes. row-key="sku" makes the SKU the key of the selection. For a server that does not fit at all, request(state, signal) replaces the whole request.

New product

selected

Products from a Laravel paginator
DescriptionActions
Loading…
Loading more…

Could not load the data. Check your connection and try again.

No results

Loading, empty and error

While the data loads, the body holds one row with Loading…, or the loading slot (here a spinner with a message of its own). An answer with no rows shows No results, or the empty slot (here an empty state whose button sends table-clear). A failed request shows the error message, or the error slot, with a Try again button; the table never breaks. These tables use config.request to stay in one state.

Loading
Loading products Fetching the products from the server…
Loading more…

Could not load the data. Check your connection and try again.

No results

Empty
Loading…
Loading more…

Could not load the data. Check your connection and try again.

No products found

Try another search or clear the filters.

Error
Loading…
Loading more…

The products could not be loaded. Check your connection and try again.

No results

Server-rendered data table

A sk-data-table gets the rows of one page (data) and the state the application read from the URL (page, limit, search, sorts, filters, total), and needs no JavaScript to search, filter, sort, or page: the table sits in a GET form, Enter sends it, and the sort titles and the pagination are links that keep every parameter (?search=&filters[key]=&limit=&sorts[key]=&page=). It shows a sort by several columns (here price, then name), a caption with markup (the caption slot), a header row above the titles (the default slot), and a sticky header and footer (the foot slot). The View menu sends _hidden[] and _density with Apply. Buttons with formaction (Delete selected, the row Delete) are sent by a script through a temporary form with selected[] and the hidden inputs of the bulk actions. This example is static: its links and form are real, but the content does not change, and the actions only show a toast.

New product
Active products (page 1 of 39)
Product State
SKUName2CategoryPrice1StatusActions
sku-ilv-8263Smart Air PurifierHome$199.99 Active
sku-ncu-6787Portable Ice MakerKitchen$199.99 Active
sku-dkw-7761Kids' Learning TabletElectronics$129.99 Active
sku-ftx-8870Cat TreePets$99.99 Active
sku-nae-5384Fitness SmartwatchWearable Tech$99.99 Active
Prices exclude tax.

Server-rendered, no results

With an empty data, the body has one row across all the columns with No results, or the empty slot: here an empty state whose button is a link without parameters, so it clears the search and the filters. The table is compact and bordered, and hides the Category column (hidden-fields, which the application fills from _hidden[]; the View menu shows it checked). With one page, the status stands on its own and there is no pagination.

Discontinued products
SKUNamePrice

No products found

Nothing matches the search and the filters.

No results

Markup

The built HTML of the basic API table, before the browser runs it. It is a native <table> with a caption, scope on every header and aria-sort on the sorted columns, in a focusable scroll region named by the caption; sort controls are buttons inside their header, every search and filter has a name, and the status has aria-live="polite", so a screen reader hears Showing 11 to 20 of 1000 results after every change.

Options reference

The props of sk-api-table, the keys of config, and the events. Every attribute that is not a prop goes to the <table>.

Name Kind Meaning
url Prop The API endpoint the table loads.
fields Prop The columns: { key, text, align, sortable, sticky, format }.
row-key Prop The field that identifies a row for the selection (default id).
limit-options Prop The rows per page choices (default [10, 25, 50, 100]); the first one is the starting value.
searchable, selectable, view-action, infinite Flags The search box, the row checkboxes with the bulk actions, the View menu, and the infinite list.
caption, variant, density, sticky-header, sticky-footer, striped, hover, bordered Props The look, as on the Tables page; variant defaults to primary.
config.headers Config An object, or a function called on every request, merged with the JSON headers.
config.params(state) Config The query string object, from { page, limit, search, filters, sorts }.
config.parse(response) Config Returns { rows, page, lastPage, from, to, total, hasNext }.
config.map(row) Config Changes each row.
config.request(state, signal) Config Replaces the request, the params, the parse, and the map at once.
config.format Config The cell formats by column key, { key: (value, row) => content }.
table-bulk Event from the table A button in the bulk-actions slot was clicked: detail: { action, selected }.
table-reload Event to the table Loads again with the same state and clears the selection.
table-clear Event to the table Empties the search and the filters, and loads again from page 1.