Function: gridOptions()
gridOptions<
Row>(spec,rows,o?):SdvGridOptions<Row>
Defined in: packages/sdvtables/src/aggrid.ts:209
An sdvtables spec as AG Grid options: createGrid(el, gridOptions(spec, rows, { theme: themeQuartz })), or
<AgGridReact {...gridOptions(spec, rows, { theme: themeQuartz })} />.
- Columns: one
ColDefper spec column, with the HTML table's label, alignment and pxwidth; numbers (num,int,pct,rank, and ascaleNote's divisor and label suffix) keep sdvtables' formats, filter as numbers, and sort with sdvtables' own comparator, missing values last both ways (a blank number is missing, never 0). - Images:
logo,wordmarkandheadshotcolumns draw<img>cellsheightpx tall, in plain JavaScript and in ag-grid-react alike. A team or player with no image keeps its text, with one warning. Team values may be abbreviations, names or numeric ids. - Team colours:
teamColorBgandteamColorBarcolumns, and whole rows withteamRows, take sdvplot's team palette for the theme's background, with black or white text by contrast; a team row keeps a shade of its fill when AG Grid hovers or selects it. - Theme: with
theme(AG Grid'sthemeQuartz, say), the theme's fonts, colours, header style, rules, stripes and colour scheme as AG Grid theme params; its density as the row height.
Other column kinds (pills, bars, sparklines...) show their plain value, with one warning per kind. Synchronous: call
await prepare(spec) (@sportsdataverse/sdvtables/html) first. Images and colours are worked out once, from
rows: build the options again when the rows change. Community features only (MIT ag-grid-community):
register AllCommunityModule; nothing here needs AG Grid Enterprise.
Type Parameters
Row
Row
Parameters
spec
TableSpec<Row>
rows
readonly Row[]
o?
GridOptionsOptions<Row> = {}
Returns
SdvGridOptions<Row>
Example
import { AllCommunityModule, ModuleRegistry, themeQuartz } from "ag-grid-community";
import { defineTable } from "@sportsdataverse/sdvtables";
import { gridOptions } from "@sportsdataverse/sdvtables/aggrid";
import { prepare } from "@sportsdataverse/sdvtables/html";
ModuleRegistry.registerModules([AllCommunityModule]);
// 2024 regular season, nflverse games
const rows = [
{ team: "KC", wins: 15, pf: 385, pa: 326 },
{ team: "BUF", wins: 13, pf: 525, pa: 368 },
{ team: "LAC", wins: 11, pf: 402, pa: 301 },
];
const spec = defineTable<(typeof rows)[number]>()
.columns((c) => [c.logo("team", { league: "nfl", height: 28 }), c.int("wins"), c.int("pf"), c.int("pa")])
.theme("sdv")
.rowKey("team")
.build();
await prepare(spec);
const options = gridOptions(spec, rows, { theme: themeQuartz, teamRows: { key: "team", league: "nfl" } });
// in the page: createGrid(document.querySelector("#grid"), options), from ag-grid-community
options.columnDefs.map((c) => [c.headerName, c.cellDataType]);