Public
Edited
Oct 16, 2024
4 forks
25 stars
Insert cell
Insert cell
Insert cell
Insert cell
viewof demo = table(cars)
Insert cell
Insert cell
table(cars, {
sort: 'Miles_per_Gallon'
})
Insert cell
Insert cell
{
const element = table(cars);
element.hot.updateSettings({
afterSelection: (row, column, row2, column2) => {
mutable selection = element.hot.getData(row, column, row2, column2);
}
});
return element;
}
Insert cell
mutable selection = []
Insert cell
Insert cell
table([...cars, []], {
columnSummary: Object.values(cars[0]).map((value, index) => ({
destinationRow: cars.length,
destinationColumn: index,
type: typeof value === 'string' ? 'count' : 'sum'
}))
})
Insert cell
Insert cell
{
const output = /worker-(.+)\.html/.exec(window.location.href)[1];
const cache = () =>
localStorage.getItem(output)
? JSON.parse(localStorage.getItem(output))
: cars;
const element = table(cache());
element.hot.updateSettings({
afterChange: (changes, source) => {
if (source !== "loadData") {
localStorage.setItem(
output,
JSON.stringify(element.hot.getSourceData(), null, 2)
);
}
},
contextMenu: [
{
name: "<b>Discard edits</b>",
hidden: () => {
return !cache();
},
callback: (key, selection, clickEvent) => {
localStorage.clear();
element.hot.loadData(cars);
}
},
{
name: "---------",
hidden: () => !cache()
},
"row_above",
"row_below",
"---------",
"col_left",
"col_right",
"---------",
"remove_row",
"remove_col",
"---------",
"undo",
"redo",
"---------",
"make_read_only",
"---------",
"alignment"
]
});
return element;
}
Insert cell
Insert cell
cars = require('@observablehq/cars')
Insert cell
import { table } from '@gnestor/table'
Insert cell
import { localStorage } from '@mbostock/safe-local-storage'
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