Skip to main content

Function: dataGridProps()

dataGridProps<Row>(spec, rows, o?): SdvDataGridProps<Row>

Defined in: packages/sdvtables/src/mui.ts:192

An sdvtables spec as MUI X Data Grid props: <DataGrid rows={rows} {...dataGridProps(spec, rows)} />.

  • Columns: one GridColDef per spec column, with the HTML table's label, alignment and px width; numbers (num, int, pct, rank) keep sdvtables' formats and sort as numbers.
  • Images: logo, wordmark and headshot columns draw <img> cells height px tall. A team or player with no image keeps its text, with one warning. Team values may be abbreviations, names or numeric ids.
  • Team colours: teamColorBg and teamColorBar columns, and whole rows with teamRows, take sdvplot's team palette for the theme's background, with black or white text by contrast.
  • Theme: the theme's fonts, colours, header style, rules and stripes as the grid's sx, its density as MUI's.

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 props again (or useMemo on rows) when the rows change. MIT @mui/x-data-grid only: nothing here needs the Pro or Premium packages.

Type Parameters​

Row​

Row

Parameters​

spec​

TableSpec<Row>

rows​

readonly Row[]

o?​

DataGridPropsOptions<Row> = {}

Returns​

SdvDataGridProps<Row>

Example​

import { DataGrid } from "@mui/x-data-grid";
import { defineTable } from "@sportsdataverse/sdvtables";
import { prepare } from "@sportsdataverse/sdvtables/html";
import { dataGridProps } from "@sportsdataverse/sdvtables/mui";

// 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);
<DataGrid rows={rows} {...dataGridProps(spec, rows, { teamRows: { key: "team", league: "nfl" } })} />;