UNPKG

@1771technologies/lytenyte-pro

Version:

Blazingly fast headless React data grid with 100s of features.

24 lines (23 loc) 921 B
import { get } from "@1771technologies/lytenyte-shared"; export const makeColumnField = (grid) => { return (c, d) => { const meta = grid.state.columnMeta.get(); const column = typeof c === "string" ? meta.columnLookup.get(c) : c; if (!column) { console.error(`Attempting to compute the field of a column that is not defined: ${c}`); return null; } const field = column.field ?? column.id; if (d.kind === "branch") { if (typeof field === "function") return field({ column, data: d, grid }); return d.data?.[column.id]; } const fieldType = typeof field; if (fieldType === "string" || fieldType === "number") return d.data?.[field]; if (fieldType === "object") return get(d.data, field.path); return field({ column, data: d, grid }); }; };