Skip to main content

Getting started

This guide builds a minimal Users list: Go columns + list endpoints and a React page that loads them.

Prerequisites​

  • Go version from the module go.mod
  • PostgreSQL with the unaccent extension (for text filters)
  • React app with shadcn/ui, React Query, and nuqs
CREATE EXTENSION IF NOT EXISTS unaccent;

1. Install packages​

Go

go get github.com/izetmolla/datatable

React (shadcn CLI)

bunx shadcn@latest add https://raw.githubusercontent.com/izetmolla/datatable/main/registry/v1.json

See Install with shadcn CLI for the GitHub owner/repo/item form and dry-run tips.

In a monorepo you can replace the Go module to the local package:

replace github.com/izetmolla/datatable => ../../pkg/datatable

2. Define columns​

func usersColumns() []datatable.Column {
return []datatable.Column{
{ID: "id", AccessorKey: "id", Hidden: true, EnableSorting: true},
{
ID: "email", AccessorKey: "email", SQLColumn: "email",
Header: "Email", EnableSorting: true, EnableColumnFilter: true,
Meta: &datatable.ColumnMeta{
Label: "Email", Variant: datatable.VariantText,
Placeholder: "Search email...",
},
},
{
ID: "created_at", AccessorKey: "created_at",
Header: "Created", EnableSorting: true, EnableColumnFilter: true,
Meta: &datatable.ColumnMeta{Label: "Created", Variant: datatable.VariantDateRange},
},
}
}

3. Expose columns + list APIs​

func GetColumns(c fiber.Ctx) error {
return c.JSON(datatable.GetColumns(usersColumns()))
}

func GetList(c fiber.Ctx) error {
columns := usersColumns()
q, err := fiberv3query.Extract(c, columns)
if err != nil {
return c.Status(400).JSON(fiber.Map{"error": err.Error()})
}

rows, pagination, err := postgresql.FindRaw[map[string]any](
db, q, columns, "users",
).Run()
if err != nil {
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
}

return c.JSON(fiber.Map{
"data": rows,
"pagination": datatable.RenderPagination(pagination),
})
}

4. React page​

const { columns, isLoading, error, columnVisibility } = useBackendColumns<User>({
fetchColumns: () => getUsersColumns(),
queryKey: ["users", "columns"],
});

<DataTable<User>
columns={columns}
source={{
type: "server",
options: {
fetch: (params) => getUsersList(params),
queryKey: (params) => ["users", "list", params],
initialPerPage: 10,
initialSorting: [{ id: "created_at", desc: true }],
},
}}
initialState={{
sorting: [{ id: "created_at", desc: true }],
columnVisibility,
}}
getRowId={(r) => r.id}
enableToolbar
enableAdvancedFilter
enablePagination
/>

5. Verify the contract​

  1. Open the page — columns load, then rows.
  2. Type in a text filter — URL updates, list refetch fires.
  3. Inspect the request: you should see pagination[page], sorting, and columnFilters (or filters in advanced mode).

Next: Architecture · Go quick start · React quick start · End-to-end