Public
Edited
Oct 18, 2024
1 fork
Importers
3 stars
Insert cell
Insert cell
tableWithFormulae = composeTable([withFormulae])
Insert cell
tableWithCheckbox = composeTable([withCheckbox])
Insert cell
tableWithHtml = composeTable([withHtml])
Insert cell
Insert cell
composeTable = (transforms = [], hooks = []) =>
(data, options = {}) => {
if (data) {
for (let transform of transforms) {
data = transform.data(data);
options = transform.options(options);
}
const element = table(data, options);
for (let hook of hooks) {
element.hot.updateSettings(hook(element.hot));
}
return element;
}
}
Insert cell
Insert cell
withFormulae = ({
data: (data) => data,
options: (options) => ({
...options,
colHeaders: true,
rowHeaders: true,
formulas: {
engine: hf,
sheetName: "Sheet1"
}
})
})
Insert cell
withCheckbox = ({
data: (data) =>
data.map((item) => ({
checked: true,
...item
})),
options: (options) => ({
...options,
columns: (columns) => {
if (options.columns) {
columns = options.columns(columns);
}
return columns.map((column) => {
if (column.data === "checked") {
return { ...column, renderer: "checkbox" };
}
return column;
});
},
fixedColumnsLeft: 1
})
})
Insert cell
withHtml = ({
data: (data) =>
data.map((row) =>
Object.entries(row).reduce(
(result, [key, value]) => ({
...result,
[key]:
value && typeof value === "object" && value.nodeType !== undefined
? value.innerHTML
: value
}),
{}
)
),
options: (options) => ({
...options,
columns: (columns) => {
if (options.columns) {
columns = options.columns(columns);
}
return columns.map((column) => ({ ...column, renderer: "html" }));
}
})
})
Insert cell
Insert cell
Insert cell
currencyColumn = (columnName) => ({
data: columnName,
renderer: "numeric",
type: "numeric",
numericFormat: {
pattern: "$0,0.00",
culture: "en-US"
}
})
Insert cell
percentageColumn = (columnName) => ({
data: columnName,
renderer: "numeric",
type: "numeric",
numericFormat: {
pattern: "0,0.00%"
}
})
Insert cell
numberColumn = (columnName) => ({
data: columnName,
renderer: "numeric",
type: "numeric",
numericFormat: {
pattern: "0,0"
}
})
Insert cell
htmlColumn = (columnName) => ({
data: columnName,
renderer: "html"
})
Insert cell
Insert cell
hf = HyperFormula.buildEmpty()
Insert cell
import { table } from "@gnestor/table"
Insert cell
import { HyperFormula } from "@gnestor/hyperformula"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more