Table Methods
Methods on the object returned by useTable(...).init().
const table = await useTable(page.locator('#my-table'), config).init();→ API: Config Options · API: SmartRow
Lifecycle
init
Signature
init(options?: { timeout?: number }): Promise<TableResult>Parameters
options- Optional timeout for header resolution (default: 3000ms)
Resolves column headers and prepares the table for use. Must be called before any sync methods (getRow, getRowByIndex). Async methods auto-initialize if needed.
const table = await useTable(locator, config).init();
const table = await useTable(locator, config).init({ timeout: 5000 });isInitialized
Signature
isInitialized(): booleanReturns true if init() has completed successfully.
if (!table.isInitialized()) await table.init();reset
Signature
reset(): Promise<void>Resets table state (clears cached page position) and calls the onReset strategy if configured. Use after iteration to restore the table to its first page.
await table.reset();revalidate
Signature
revalidate(): Promise<void>Re-scans headers and rebuilds the column map without resetting pagination state. Use when columns change visibility or order dynamically (e.g., after toggling column visibility).
await table.revalidate();Row Access
getRow
Signature
getRow(
filters: Record<string, FilterValue>,
options?: { exact?: boolean }
): SmartRowFinds a row on the current page only by column filters. Returns synchronously — does not paginate.
const row = table.getRow({ Name: 'John Doe' });
const email = await row.getCell('Email').innerText();WARNING
getRow only searches the currently visible page. Use findRow to search across pages.
getRowByIndex
Signature
getRowByIndex(index: number): SmartRowParameters
index- 0-based row index
Gets a row by 0-based index on the current page. The returned SmartRow has its rowIndex set, enabling bringIntoView().
const firstRow = table.getRowByIndex(0);findRow
Signature
findRow(
filters: Record<string, FilterValue>,
options?: { exact?: boolean, maxPages?: number }
): Promise<SmartRow>Parameters
filters- The filter criteria to matchoptions- Search options including exact match and max pages
Searches for a single matching row across pages. Paginates automatically. Returns the first match.
const row = await table.findRow({ Email: 'john@example.com' });
const row = await table.findRow({ Status: 'Active' }, { maxPages: 10 });findRows
Signature
findRows(
filters?: Record<string, FilterValue>,
options?: { exact?: boolean, maxPages?: number }
): Promise<SmartRowArray<T>>Parameters
filters- The filter criteria to match (omit or pass {} for all rows)options- Search options including exact match and max pages
Searches for all matching rows across pages. Pass empty filters {} or omit to collect every row.
const activeRows = await table.findRows({ Status: 'Active' });
const allRows = await table.findRows();Iteration
forEach
Signature
forEach(
callback: (ctx: RowIterationContext<T>) => void | Promise<void>,
options?: RowIterationOptions
): Promise<void>Parameters
callback- Function receivingoptions- maxPages, concurrency, dedupe, useBulkPagination
Iterates every row across all pages. Runs sequentially by default. Call stop() in the callback to halt early (stops after the current page finishes).
await table.forEach(async ({ row, stop }) => {
const status = await row.getCell('Status').innerText();
if (status === 'Archived') stop();
await row.getCell('Checkbox').click();
});map
Signature
map<R>(
callback: (ctx: RowIterationContext<T>) => R | Promise<R>,
options?: RowIterationOptions
): Promise<R[]>Parameters
callback- Function receivingoptions- maxPages, concurrency, dedupe, useBulkPagination
Transforms every row across all pages into a value. Runs in parallel by default (safe for reads). Use concurrency: 'sequential' when callbacks interact with UI.
const emails = await table.map(({ row }) => row.getCell('Email').innerText());
// UI interactions — use sequential
const results = await table.map(async ({ row }) => {
await row.getCell('Actions').locator('button').click();
return page.locator('.dialog .title').innerText();
}, { concurrency: 'sequential' });filter
Signature
filter(
predicate: (ctx: RowIterationContext<T>) => boolean | Promise<boolean>,
options?: RowIterationOptions
): Promise<SmartRowArray<T>>Collects rows matching an async predicate across all pages. Returns a SmartRowArray.
const highEarners = await table.filter(async ({ row }) => {
const salary = await row.getCell('Salary').innerText();
return parseInt(salary.replace(/\D/g, '')) > 50000;
});Async iteration
The table implements AsyncIterable, so you can use for await...of for fine-grained control with break:
for await (const { row, rowIndex } of table) {
if (await row.getCell('Status').innerText() === 'Archived') break;
}Column Utilities
getHeaders
Signature
getHeaders(): Promise<string[]>Returns the resolved column header names in order.
const headers = await table.getHeaders();
// ['Name', 'Email', 'Status', ...]getHeaderCell
Signature
getHeaderCell(columnName: string): Promise<Locator>Returns a Locator for the header cell of a named column.
const nameHeader = await table.getHeaderCell('Name');
await nameHeader.click(); // sort by NamescrollToColumn
Signature
scrollToColumn(columnName: string): Promise<void>Scrolls horizontally to bring a column into view. Uses the configured navigation strategy.
await table.scrollToColumn('Notes');countRows
Signature
countRows: () => Promise<number>Returns the number of rows currently visible on the page. Does not paginate.
const count = await table.countRows();mapColumn
Signature
mapColumn<R = string>(columnName: string, options?: RowIterationOptions): Promise<R[]>Parameters
columnName- The name of the column to extractoptions- Iteration options
Extracts all values for a single column across pages. More efficient than map + toJSON for single-column reads.
const statuses = await table.mapColumn('Status');
const counts = await table.mapColumn<number>('Count');getColumnValues
Signature
getColumnValues(columnName: string, options?: RowIterationOptions): Promise<string[]>Parameters
columnName- The name of the column to extractoptions- Iteration options
Extracts all values for a single column as strings. Convenience wrapper around mapColumn.
const names = await table.getColumnValues('Name');Sorting
sorting.apply
Signature
sorting?: SortingStrategyApplies the configured sorting strategy to a column.
await table.sorting.apply('Name', 'asc');
await table.sorting.apply('Created At', 'desc');Diagnostics
generateConfig
Signature
generateConfig: () => Promise<void>Dumps table HTML and TypeScript type definitions to help generate PST configuration. Intentionally throws an error containing the prompt — copy the output and pass it to an AI assistant.
await table.generateConfig();