Data grid / foldkit-data-grid

Over a foldkit-crud list

foldkit-data-grid/crud reads a Crud.list and the Remote page it reads in the grid's terms. Remote still owns the page, its loading, its retries and its next page; this subpath fetches nothing and holds nothing.

ts
import { GridCrud } from 'foldkit-data-grid/crud'

const columns = GridCrud.columns(Posts) // a Crud.list
const Grid = DataGrid.make({ id: 'posts', columns })

const rows = GridCrud.rows(page, post => post.id) // page: RemoteData<Page<Row>>
const status = GridCrud.status(page) // RowStatus: Ready, Loading, Refreshing, Failed
  • GridCrud.columns(list, { columns, words }) is a column per listed member, headed by its label, its value the member's text as its Display says it; a hidden Display (usually the id) starts hidden. columns adds what only the grid knows, per member: pinned, width, edit, a header of its own, or hidden: false. The value stays the Display's.
  • GridCrud.rows(page, key) is the page's rows in its order. A page with more after it counts as unknown, at least its rows; a failed read keeps the rows it had. The same page value gives the same row model, so what is built from it is kept across renders.
  • GridCrud.status(page) is a RowStatus for the view to say.
  • Sorting stays the query's. Pass foldkit-crud's sort state to the view's sort; a header sends its Message, and the application changes the query input. list.more is the view's onMore, list.refresh behind its onRetry.

The subpath needs foldkit-crud and foldkit-remote, optional peers of this package; the core works without them.

Row counts

A RowModel's count is a RowCount:

  • Known({ total }): every row is counted. Rows past the loaded ones are in range, but have no key until they load, so a move onto one finds no cell.
  • Unknown({ atLeast }): a cursor that may have more. Movement stops at the rows seen so far.