Components

Table

This renders a table with selectable rows. The function resolves with the user-selected rows.

Usage

const rows = await io.input.table(
  'Users',                          // { offset } is automatically calulated.
  async ({ offset, pageSize }) => { // This function is fired every time the user navigates table pages.
    const { count } = (await db.select({ count: count() }).from(employeesTable))[0]
    return {
      totalResults: count,
      resultsToDisplay:  await db
        .select(employeesTable)
        .fields('*') // Or specify specific fields if needed
        .limit(pageSize)
        .offset(offset)
    }
  },
)
console.log(rows)

Parameters

labelrequired
string

The label to render above the input.

query
(input: { query: string, page: number, offset: number, pageSize: number }) => Promise<{resultsToDisplay: Array<JsonValue>, totalResults: number}>

An asynchronous function that receives { query: string, page: number, offset: number, pageSize: number } as input and outputs the resulting rows to display and a count of total results.

query
string

Represents the query entered by the user.

page
number

Represents the page the user is on.

offset
number

Represents the automatically calculated item offset. This calculation is based on page size and the total number of records. const offset = (page - 1) * pageSize

pageSize
number

Represents the amount of items to render on each page. Inherited from the options.resultsPerPage parameter.

options { ... }
resultsPerPage
number

The number of rows to render on each page. Default 100.

defaultValue
Array<JsonValue>

Default value rendered in input. Default [].

filterPlaceholder
string

The placeholder to display in the query input field. Default undefined.

filterable
boolean

Render a search bar to filter rows. Default true.

columns
{ key: string, label: string, sortable?: boolean, direction?: 'asc' | 'desc' }

The columns parameter is used to map specific column names and behaviors. Default undefined.

customValidator
(input: unknown) => Promise<string | true>

An asynchronous function that takes unknown input and outputs either true or an error message string to show the user.