@gridsay/tanstack-table describes a TanStack Table v9 table to Gridsay, posts a question and applies the answer. It ships no interface. @gridsay/tanstack-table/react re-exports everything in the core entry and adds the useTableAssistant hook.
import { assistantColumn, assistantFilter, assistantSort, assistantGroupedRowModel, createTableAssistant, GridsayError, CANNOT_APPLY_CODE, RESET_CODE,} from '@gridsay/tanstack-table';import { useTableAssistant } from '@gridsay/tanstack-table/react';| Export | Entry | What it is |
|---|---|---|
useTableAssistant | /react | The React hook. |
createTableAssistant | both | The assistant without React. |
assistantColumn | both | Column defaults: the plugin's filter and sort functions. |
assistantFilter | both | The filter function. |
assistantSort | both | The sort function. |
assistantGroupedRowModel | both | The grouped row model the assistant groups with. |
GridsayError | both | The error class every failure uses. |
CANNOT_APPLY_CODE, RESET_CODE, CONNECTION_FAILED_CODE, NOT_JSON_CODE, INVALID_ANSWER_CODE, UNAUTHENTICATED_USER_CODE, UNEXPECTED_ERROR_CODE | both | The plugin's own error codes. |
CANNOT_APPLY, RESET, CONNECTION_FAILED, NOT_JSON, INVALID_ANSWER, UNAUTHENTICATED_USER | both | The plugin's default messages. Do not compare them. |
AssistantColumnMeta, AssistantTable, ColumnType, TableAssistant, TableAssistantOptions | both | Types. |
TableAssistantState | /react | The hook's return type. |
useTableAssistant(table, options): pass your table and the options. The hook keeps one conversation while the component stays mounted, and reads the latest table and options for every question. It returns six fields:
| Field | Type | Behaviour |
|---|---|---|
ask | (question: string) => Promise<boolean> | Resolves true once the answer is on the table, false when it is not; error then says why, unless reset() was called. Questions go one at a time, in order. |
undo | () => boolean | Puts back what the last answer changed and returns true. Returns false and does nothing when there is nothing to undo or a question is pending. Synchronous. |
reset | () => void | Starts a new conversation, forgets the answer to undo and clears error. The table stays as it is. |
canUndo | boolean | true after an applied answer; false while a question is pending. A refusal leaves it as it was. |
pending | boolean | true while a question is being answered or waits its turn. |
error | GridsayError | null | Why the last question failed, or null. Clears when the next ask starts, when undo puts something back, and on reset(). |
There is no other field. Show error.message, not the error object.
createTableAssistant(table, options) is for a table made by another v9 adapter. It returns four fields:
| Field | Type | Behaviour |
|---|---|---|
ask | (question: string) => Promise<void> | Resolves once the answer is on the table. Rejects with a GridsayError, with code reset when reset() came while it waited. |
undo | () => boolean | As the hook's. |
reset | () => void | As the hook's. |
canUndo | readonly boolean | Read assistant.canUndo when you need it; a destructured copy does not update. |
import { createTableAssistant, GridsayError, RESET_CODE } from '@gridsay/tanstack-table'; // Inside your integration, `table` is the configured v9 table.const assistant = createTableAssistant(table, { url: '/api/tanstack-table' });try { await assistant.ask('Orders over 500, biggest first');} catch (error) { if (!(error instanceof GridsayError)) throw error; if (error.code !== RESET_CODE) showMessage(error.message);}showMessage stands for your own interface code. The core entry is tested with React's adapter only.
Both take the same options:
| Option | Type | Meaning |
|---|---|---|
url | string, required | Where the question is posted: your route, or Gridsay's prompt endpoint with a publishable key. |
headers | an object, or a function returning one, sync or async | Extra request headers, read for every question. If the function throws, nothing is sent and the code is unexpected_error. |
publishableKey | string | For calls from the browser: sent as x-api-key. Never a secret key. |
getToken | () => string | null | undefined, sync or async | For calls from the browser: the signed-in user's token, sent as a bearer token. null, undefined or an empty string means signed out: nothing is sent, and the code is unauthenticated_user. |
additionalContext | string | Notes about the table, up to 20,000 characters. |
privateMode | boolean | Sent as options.privateMode. |
referenceId | string | Your id for the end user, up to 127 characters. |
Browser calls also need the key's allowed origins and an end-user sign-in method: see Browser keys.
Set it as the table's defaultColumn, or spread it into the columns the assistant may filter and sort. Its whole value:
{ filterFn: assistantFilter, sortFn: assistantSort, sortUndefined: false }assistantFilter, (row, columnId, filterValue) => boolean, runs the filters an answer set and keeps every row for any other filter value. Its resolveFilterValue prepares a filter once rather than per row. The operators are listed on Filtering.assistantSort, (rowA, rowB, columnId) => number, orders cells by type, empty first, ties in data order. See Sorting.filterFn cannot be filtered by the assistant, and one with its own sortFn cannot be sorted by it unless the table uses manualSorting.assistantGroupedRowModel() takes no arguments. Register it as groupedRowModel beside columnGroupingFeature, in place of createGroupedRowModel(). Without it, grouping is off for the assistant unless the table uses manualGrouping. See Grouping.
| Field | Type | Meaning |
|---|---|---|
type | 'string' | 'number' | 'date' | 'dateTime' | 'boolean' | 'singleSelect' | Wins over the type read from the first 100 rows. |
description | string | Sent with every question. |
options | (string | number | { value, label })[] | A singleSelect's choices; at most 500 are sent. |
examples | unknown[] | true | A list sends its first 20; true sends up to five values from the rows. Off by default. |
Details and what leaves your app: Describing columns.
| Answer | Needs on the table | Changes |
|---|---|---|
| Filters | columnFilteringFeature, filteredRowModel, assistantFilter on the column, no manualFiltering | Replaces columnFilters; clears globalFilter. |
| Sorting | rowSortingFeature with sortedRowModel and assistantSort, or manualSorting | Replaces sorting. |
| Grouping | columnGroupingFeature with assistantGroupedRowModel(), or manualGrouping | Replaces grouping. |
| Top rows selected | rowSelectionFeature, enableRowSelection not false | Replaces rowSelection. |
An answer is applied in full or not at all, unless reset() comes while it is being applied. State you control must show it within one second: see Controlled state.
| Field | Type | Use |
|---|---|---|
name | 'GridsayError' | Check with instanceof GridsayError. |
message | string | The sentence to show your user. |
code | string | undefined | What happened. Compare codes, never messages. A route of your own may send none. |
status | number | undefined | The HTTP status, when a response arrived. |
retryAfter | number | undefined | Seconds to wait, when Gridsay sets it. |
detail | string | undefined | An explanation for you. Never show it to users. |
cause | unknown | What was thrown, when something was. |
Every code, its cause and whether it is charged: Refusals and errors.
| What | Limit |
|---|---|
| Question | 1 to 8,000 characters |
additionalContext | 20,000 characters |
referenceId | 127 characters |
| Column id | 255 characters; longer ids are not sent |
Options per singleSelect | 500; values and labels up to 255 characters |
examples | the first 20 of a list, or five read from the rows |
The column descriptions sent as context | 1,000,000 characters |
| Request body | 2 MB |
| What reaches the model: instructions, columns, state, question and notes | 73,728 bytes; earlier turns of the conversation are cut to fit |
| Controlled state taking an answer | 1 second |
| Undo | one answer |
Over a size limit, Gridsay answers 413 context_too_large before the model, and the question is not charged. Rate and usage limits are on Limits.
| Package | Supported |
|---|---|
@tanstack/table-core | ^9.3.1: v9 from 9.3.1. Tested with 9.3.1. |
@tanstack/react-table | v9 from 9.3.1. Tested with 9.3.1. |
| React | 18 or later, for /react. Optional for the core entry. |
| TanStack Table v8 | Not supported, nor Material React Table and Mantine React Table, which are built on it. |
| Other v9 adapters | The core entry works with any v9 table; tested with React only. |
Before 1.0, a breaking change raises the minor version. Gridsay is an independent product, not affiliated with or endorsed by the TanStack Table project.