@8sheets/data-grid 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +36 -0
- package/README.md +52 -2
- package/a11y/cell-alt-text.js +1 -0
- package/api/overlay.js +1 -0
- package/api/serialize.js +1 -0
- package/api/skins.js +1 -0
- package/api/style-refs.js +1 -0
- package/api/watermark-xml.js +2 -0
- package/calc/adjust.js +1 -0
- package/calc/cell-set.js +1 -0
- package/calc/compile.js +1 -0
- package/calc/engine.js +1 -0
- package/calc/fill-shape.js +2 -0
- package/calc/functions/array.js +1 -0
- package/calc/functions/database.js +1 -0
- package/calc/functions/date.js +1 -0
- package/calc/functions/engineering.js +1 -0
- package/calc/functions/financial.js +1 -0
- package/calc/functions/helpers.js +1 -0
- package/calc/functions/index.js +1 -0
- package/calc/functions/info.js +1 -0
- package/calc/functions/logical.js +1 -0
- package/calc/functions/lookup.js +1 -0
- package/calc/functions/math.js +1 -0
- package/calc/functions/registry.js +1 -0
- package/calc/functions/stat.js +1 -0
- package/calc/functions/text.js +1 -0
- package/calc/parser.js +3 -0
- package/calc/values.js +1 -0
- package/calcx/ai/client.js +1 -0
- package/calcx/ai/functions.js +15 -0
- package/calcx/ai/settings.js +1 -0
- package/calcx/async.js +1 -0
- package/calcx/culture/format-locale.js +1 -0
- package/calcx/culture/lcid.js +1 -0
- package/calcx/external-read.js +1 -0
- package/calcx/external-write.js +3 -0
- package/calcx/external.js +1 -0
- package/calcx/functions/dynamic.js +1 -0
- package/calcx/functions/ets.js +1 -0
- package/calcx/functions/index.js +1 -0
- package/calcx/functions/misc.js +1 -0
- package/calcx/functions/text.js +1 -0
- package/calcx/functions/xml.js +1 -0
- package/calcx/refresh.js +1 -0
- package/cells/auto-merge.js +1 -0
- package/cells/axis-limits.js +1 -0
- package/cells/axis-ops.js +1 -0
- package/cells/background-xml.js +1 -0
- package/cells/background.js +1 -0
- package/cells/book-css.js +206 -0
- package/cells/book-read.js +1 -0
- package/cells/book-view.js +1 -0
- package/cells/cell-defaults.js +1 -0
- package/cells/cell-extras.js +1 -0
- package/cells/cell-options-ui.js +1 -0
- package/cells/cell-styles-xml.js +1 -0
- package/cells/cf-engine.js +1 -0
- package/cells/cf-file.js +1 -0
- package/cells/cf-paint.js +1 -0
- package/cells/consolidate-links.js +1 -0
- package/cells/docprops-xml.js +2 -0
- package/cells/filter-file.js +1 -0
- package/cells/find-engine.js +2 -0
- package/cells/find.js +1 -0
- package/cells/format-code.js +1 -0
- package/cells/format-panes.js +3 -0
- package/cells/format-tabs.js +102 -0
- package/cells/goto.js +1 -0
- package/cells/header-colors.js +1 -0
- package/cells/mask.js +1 -0
- package/cells/menu-extras.js +1 -0
- package/cells/name-box.js +1 -0
- package/cells/note-xml.js +1 -0
- package/cells/options.js +1 -0
- package/cells/outline-column.js +1 -0
- package/cells/paint.js +1 -0
- package/cells/panes.js +1 -0
- package/cells/rich-data-xml.js +2 -0
- package/cells/rich-data.js +1 -0
- package/cells/rich-runs.js +2 -0
- package/cells/rich-values.js +1 -0
- package/cells/rich-xml.js +1 -0
- package/cells/rounded.js +1 -0
- package/cells/sections.js +2 -0
- package/cells/selection-modes.js +1 -0
- package/cells/style-xml.js +1 -0
- package/cells/text-layout.js +8 -0
- package/cells/undo-group.js +1 -0
- package/cells/validation-alert.js +2 -0
- package/cells/view-options.js +1 -0
- package/cells/view-xml.js +1 -0
- package/celltypes/barcode-tables.js +31 -0
- package/celltypes/barcode.js +2 -0
- package/celltypes/base.js +1 -0
- package/celltypes/cell-buttons.js +1 -0
- package/celltypes/cell-types.js +2 -0
- package/celltypes/data-object.js +1 -0
- package/celltypes/diagonal.js +1 -0
- package/celltypes/dropdowns-more.js +13 -0
- package/celltypes/dropdowns.js +42 -0
- package/celltypes/file-cell.js +2 -0
- package/celltypes/glyphs.js +1 -0
- package/celltypes/persist.js +2 -0
- package/celltypes/range-template.js +2 -0
- package/charts/chartex.js +3 -0
- package/charts/geo/geo-xml.js +1 -0
- package/charts/geo/map-state.js +1 -0
- package/charts/patterns.js +1 -0
- package/core/address.js +1 -0
- package/core/axis.js +1 -0
- package/core/base64.js +1 -0
- package/core/changes.js +1 -0
- package/core/color.js +1 -0
- package/core/cond-format.js +1 -0
- package/core/custom-views.js +1 -0
- package/core/default-names.js +1 -0
- package/core/formula-refs.js +1 -0
- package/core/formula-store.js +1 -0
- package/core/input.js +1 -0
- package/core/math.js +1 -0
- package/core/numfmt.js +1 -0
- package/core/online.js +1 -0
- package/core/protection.js +1 -0
- package/core/regexp.js +1 -0
- package/core/sheet-group.js +1 -0
- package/core/sheet.js +1 -0
- package/core/sparklines.js +1 -0
- package/core/sparse.js +1 -0
- package/core/strings.js +1 -0
- package/core/styles.js +1 -0
- package/core/table-presets.js +7 -0
- package/core/tables.js +2 -0
- package/core/tsv.js +4 -0
- package/core/whatif.js +1 -0
- package/core/workbook.js +1 -0
- package/datasheets/bind.js +1 -0
- package/datasheets/calendar.js +1 -0
- package/datasheets/cross.js +1 -0
- package/datasheets/data-core.js +1 -0
- package/datasheets/data.js +1 -0
- package/datasheets/formula.js +1 -0
- package/datasheets/gantt-paint.js +1 -0
- package/datasheets/gantt-resources.js +1 -0
- package/datasheets/gantt-shapes.js +1 -0
- package/datasheets/gantt.js +1 -0
- package/datasheets/manager.js +1 -0
- package/datasheets/path-binding.js +2 -0
- package/datasheets/persist-writer.js +2 -0
- package/datasheets/persist.js +1 -0
- package/datasheets/query-function.js +1 -0
- package/datasheets/remote.js +3 -0
- package/datasheets/report-entry.js +1 -0
- package/datasheets/report.js +1 -0
- package/datasheets/rules.js +1 -0
- package/datasheets/sort.js +1 -0
- package/datasheets/table-sheet.js +1 -0
- package/datasheets/view.js +3 -0
- package/datasheets/virtual-sheet.js +1 -0
- package/datasheets/window.js +1 -0
- package/extras/getdata/persist.js +2 -0
- package/extras/getdata/rows.js +1 -0
- package/extras/getdata/steps.js +1 -0
- package/i18n/dom.js +1 -0
- package/i18n/en/a11y.js +1 -0
- package/i18n/en/cells.js +1 -0
- package/i18n/en/charts.js +1 -0
- package/i18n/en/common.js +1 -0
- package/i18n/en/datasheets.js +1 -0
- package/i18n/en/format.js +1 -0
- package/i18n/en/misc.js +1 -0
- package/i18n/en/pivot.js +1 -0
- package/i18n/en/proofing.js +1 -0
- package/i18n/en/ribbon.js +1 -0
- package/i18n/en/shapes.js +1 -0
- package/i18n/en/shell.js +1 -0
- package/i18n/en/touch.js +1 -0
- package/i18n/en.js +1 -0
- package/i18n/index.js +1 -0
- package/i18n/key-text.js +1 -0
- package/i18n/languages.js +1 -0
- package/i18n/pl/a11y.js +1 -0
- package/i18n/pl/cells.js +1 -0
- package/i18n/pl/charts.js +1 -0
- package/i18n/pl/common.js +1 -0
- package/i18n/pl/datasheets.js +1 -0
- package/i18n/pl/format.js +1 -0
- package/i18n/pl/misc.js +1 -0
- package/i18n/pl/pivot.js +1 -0
- package/i18n/pl/proofing.js +1 -0
- package/i18n/pl/ribbon.js +1 -0
- package/i18n/pl/shapes.js +1 -0
- package/i18n/pl/shell.js +1 -0
- package/i18n/pl/touch.js +1 -0
- package/i18n/pl.js +1 -0
- package/io/client.js +1 -0
- package/io/crc32.js +1 -0
- package/io/crypto/aes.js +1 -0
- package/io/crypto/agile.js +2 -0
- package/io/crypto/cfb-read.js +1 -0
- package/io/crypto/cfb-write.js +1 -0
- package/io/crypto/dataspaces.js +1 -0
- package/io/crypto/errors.js +1 -0
- package/io/crypto/hash.js +1 -0
- package/io/crypto/index.js +1 -0
- package/io/crypto/package-read.js +1 -0
- package/io/crypto/package-write.js +1 -0
- package/io/crypto/spool.js +1 -0
- package/io/crypto/standard.js +1 -0
- package/io/csv.js +8 -0
- package/io/export-blocks.js +1 -0
- package/io/foreign-parts.js +1 -0
- package/io/foreign-sheets.js +2 -0
- package/io/io.worker.js +1 -0
- package/io/package-paths.js +1 -0
- package/io/plan.js +1 -0
- package/io/text-split.js +3 -0
- package/io/xlsx-read.js +1 -0
- package/io/xlsx-styles.js +2 -0
- package/io/xlsx-tail.js +1 -0
- package/io/xlsx-write.js +2 -0
- package/io/xml-escape.js +1 -0
- package/io/xml-scan.js +1 -0
- package/io/zip-reader.js +1 -0
- package/io/zip-writer.js +1 -0
- package/objects/chart-model.js +1 -0
- package/objects/dml.js +5 -0
- package/objects/drawing-xml.js +1 -0
- package/objects/picture-url.js +1 -0
- package/package.json +57 -4
- package/pivot/engine.js +1 -0
- package/pivot/xml.js +2 -0
- package/print/page-setup.js +1 -0
- package/print/paginate.js +1 -0
- package/print/pdf.js +35 -0
- package/print/render-page.js +3 -0
- package/render/patterns.js +1 -0
- package/shapes/form-xml.js +1 -0
- package/shapes/watermark.js +1 -0
- package/slicers/custom-styles.js +1 -0
- package/slicers/date-filters.js +1 -0
- package/slicers/format.js +2 -0
- package/slicers/pivot-file.js +1 -0
- package/slicers/structured.js +1 -0
- package/slicers/table-file.js +1 -0
- package/slicers/write.js +1 -0
- package/sparklines/colors.js +1 -0
- package/sparklines/data.js +1 -0
- package/sparklines/descriptor.js +1 -0
- package/sparklines/excel-paint.js +1 -0
- package/sparklines/functions.js +1 -0
- package/sparklines/paint-core.js +1 -0
- package/sparklines/paint-measure.js +1 -0
- package/sparklines/paint-other.js +2 -0
- package/sparklines/paint-series.js +1 -0
- package/sparklines/paint.js +1 -0
- package/sparklines/print.js +1 -0
- package/sparklines/rule.js +1 -0
- package/table-view/api.js +1 -0
- package/table-view/cell-editor.js +1 -0
- package/table-view/cell-format.js +1 -0
- package/table-view/chrome.js +1 -0
- package/table-view/client.js +1 -0
- package/table-view/column-drag.js +1 -0
- package/table-view/column-input.js +1 -0
- package/table-view/column-window.js +1 -0
- package/table-view/events.js +1 -0
- package/table-view/files.js +1 -0
- package/table-view/grid-keys.js +2 -0
- package/table-view/index.d.ts +4 -0
- package/table-view/index.js +1 -0
- package/table-view/labels.js +1 -0
- package/table-view/model.js +1 -0
- package/table-view/mount.js +1 -0
- package/table-view/panel.js +1 -0
- package/table-view/pivot.js +1 -0
- package/table-view/public.d.ts +841 -0
- package/table-view/quick-filter.js +1 -0
- package/table-view/reader.worker.js +1 -0
- package/table-view/remote.js +1 -0
- package/table-view/row-cache.js +1 -0
- package/table-view/row-selection.js +1 -0
- package/table-view/table-css.js +1207 -0
- package/table-view/totals.js +1 -0
- package/table-view/version.js +1 -0
- package/table-view/worksheet-table.js +1 -0
- package/ui/dialogs.js +3 -0
- package/ui/dom.js +1 -0
- package/ui/icons.js +1 -0
- package/ui/menu-base.js +1 -0
- package/ui/protection-ui.js +1 -0
- package/ui/ui-scale.js +1 -0
|
@@ -0,0 +1,841 @@
|
|
|
1
|
+
/** A field of the records, as given in `fields`. */
|
|
2
|
+
export interface TableField {
|
|
3
|
+
name: string;
|
|
4
|
+
caption?: string;
|
|
5
|
+
type?: 'any' | 'number' | 'string' | 'date' | 'boolean';
|
|
6
|
+
/** A number format, such as `'#,##0.00'`. */
|
|
7
|
+
format?: string;
|
|
8
|
+
/** Computes the field from each record, e.g. `'[@Units]*[@Price]'`. */
|
|
9
|
+
formula?: string;
|
|
10
|
+
readOnly?: boolean;
|
|
11
|
+
/** For a remote source: whether its `update` accepts this field. Local fields are editable unless read-only or computed. */
|
|
12
|
+
editable?: boolean;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
/** A field rule checked on every edit and added record, e.g. `{ type: 'whole', operator: 'between', min: 1, max: 500, message }`. */
|
|
15
|
+
validator?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A field as the grid reports it (getFields(), the sourceLoad event). `editable` says whether edits are accepted now. */
|
|
19
|
+
export interface TableFieldInfo {
|
|
20
|
+
name: string;
|
|
21
|
+
caption?: string;
|
|
22
|
+
type?: 'any' | 'number' | 'string' | 'date' | 'boolean';
|
|
23
|
+
format?: string;
|
|
24
|
+
editable?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** An aggregate of the totals row, over every matching record. */
|
|
28
|
+
export type TableTotal = 'sum' | 'average' | 'min' | 'max' | 'count';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A conditional formatting rule of a column. Bars and colour scales scale to the column's smallest and
|
|
32
|
+
* largest value among all matching records. Value rules compare numbers for number and date columns and
|
|
33
|
+
* text (case-insensitively) otherwise; the first matching one colours the cell.
|
|
34
|
+
*/
|
|
35
|
+
export type TableColumnRule =
|
|
36
|
+
| { type: 'bar'; color?: string }
|
|
37
|
+
| { type: 'scale'; colors?: [low: string, mid: string, high: string] }
|
|
38
|
+
| {
|
|
39
|
+
type: 'value';
|
|
40
|
+
op: 'gt' | 'gte' | 'lt' | 'lte' | 'between' | 'equal' | 'notEqual' | 'contains';
|
|
41
|
+
value: string | number;
|
|
42
|
+
value2?: string | number;
|
|
43
|
+
/** A theme-aware preset. Without one, `color` and `background` (any CSS colour) apply. */
|
|
44
|
+
style?: 'good' | 'bad' | 'warn' | 'info' | 'strong';
|
|
45
|
+
color?: string;
|
|
46
|
+
background?: string;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export interface TableColumnState {
|
|
50
|
+
field: string;
|
|
51
|
+
hidden?: boolean;
|
|
52
|
+
pinned?: boolean;
|
|
53
|
+
/** Width in CSS pixels, 48 to 800. Dragging a heading's edge sets it. */
|
|
54
|
+
width?: number;
|
|
55
|
+
format?: string;
|
|
56
|
+
/** This column's aggregate in the totals row. */
|
|
57
|
+
total?: TableTotal | null;
|
|
58
|
+
rules?: TableColumnRule[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* A filter. `op` is one of `contains`, `equal`, `notEqual`, `beginsWith`, `gt`, `lt`, `gte`, `lte`,
|
|
63
|
+
* `between` (with `value2`), `blank`, `notBlank`, `in` and `notIn` (with `values`).
|
|
64
|
+
*/
|
|
65
|
+
export interface TableFilter {
|
|
66
|
+
field: string;
|
|
67
|
+
op: string;
|
|
68
|
+
value?: unknown;
|
|
69
|
+
value2?: unknown;
|
|
70
|
+
values?: unknown[];
|
|
71
|
+
/** Set on a filter typed in the filter row, together with the typed `text`. */
|
|
72
|
+
quick?: boolean;
|
|
73
|
+
text?: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface TableSortKey {
|
|
77
|
+
field: string;
|
|
78
|
+
desc?: boolean;
|
|
79
|
+
}
|
|
80
|
+
export interface TableGroup {
|
|
81
|
+
field: string;
|
|
82
|
+
desc?: boolean;
|
|
83
|
+
}
|
|
84
|
+
/** The summary under the records, and in each group row. */
|
|
85
|
+
export interface TableSummary {
|
|
86
|
+
field: string;
|
|
87
|
+
agg: 'sum' | 'average' | 'min' | 'max' | 'count' | 'distinct';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The whole view: what getState() returns and setState() takes. It holds no records. */
|
|
91
|
+
export interface TableState {
|
|
92
|
+
/** Display order; pinned columns show first. */
|
|
93
|
+
columns: TableColumnState[];
|
|
94
|
+
search: string;
|
|
95
|
+
filters: TableFilter[];
|
|
96
|
+
/** Sort keys, the first one first. Sorting a grouped field also orders its groups. */
|
|
97
|
+
sort: TableSortKey[];
|
|
98
|
+
groups: TableGroup[];
|
|
99
|
+
/**
|
|
100
|
+
* Group paths toggled away from the default. Without `collapseLevel` these are the collapsed groups.
|
|
101
|
+
* A path joins a group's values from the top level down; build one with a list such as `['East']`.
|
|
102
|
+
*/
|
|
103
|
+
collapsed: string[];
|
|
104
|
+
/** Groups at this level (0 is the top) and deeper start collapsed; `collapsed` then lists the ones opened. */
|
|
105
|
+
collapseLevel?: number;
|
|
106
|
+
total: TableSummary | null;
|
|
107
|
+
/** Shows a totals row pinned under the records, with each column's `total`. */
|
|
108
|
+
totalsRow?: boolean;
|
|
109
|
+
/** Shows an input under each heading that filters its column. */
|
|
110
|
+
filterRow?: boolean;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export type TableFormat = 'xlsx' | 'csv' | 'pdf';
|
|
114
|
+
export interface TableQuery {
|
|
115
|
+
state: TableState;
|
|
116
|
+
offset: number;
|
|
117
|
+
limit: number;
|
|
118
|
+
columnOffset: number;
|
|
119
|
+
columnLimit: number;
|
|
120
|
+
signal: AbortSignal;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* One block of rows. The grid asks for blocks of 100 rows at block-aligned offsets, caches them and
|
|
124
|
+
* prefetches the next one. `count` may be left out while the total isn't known: a page with fewer rows
|
|
125
|
+
* than `limit` (or an empty one) ends the result, and the scroll height grows a block at a time until then.
|
|
126
|
+
*/
|
|
127
|
+
export interface TablePage {
|
|
128
|
+
revision?: string | number;
|
|
129
|
+
offset: number;
|
|
130
|
+
/** Rows of the whole result, including group rows. Optional while unknown. */
|
|
131
|
+
count?: number;
|
|
132
|
+
/** Matching records. Optional while unknown. */
|
|
133
|
+
matches?: number;
|
|
134
|
+
/** Records before filtering. Optional. */
|
|
135
|
+
sourceCount?: number;
|
|
136
|
+
summary: string;
|
|
137
|
+
/** Display text of each column's totals-row aggregate, over all matching records. */
|
|
138
|
+
totals?: Record<string, string>;
|
|
139
|
+
/** Smallest and largest value of columns with bar or colour-scale rules, over all matching records. */
|
|
140
|
+
stats?: Record<string, { min: number; max: number }>;
|
|
141
|
+
columns: string[];
|
|
142
|
+
columnOffset?: number;
|
|
143
|
+
columnCount?: number;
|
|
144
|
+
collapsed?: string[];
|
|
145
|
+
rows: (
|
|
146
|
+
| { id: string | number; values: string[]; raw?: unknown[] }
|
|
147
|
+
| { group: string; path: string; level: number; collapsed: boolean; summary: string }
|
|
148
|
+
)[];
|
|
149
|
+
}
|
|
150
|
+
export interface TableDataSource {
|
|
151
|
+
update?(request: {
|
|
152
|
+
state: TableState;
|
|
153
|
+
revision: string | number;
|
|
154
|
+
cells: { id: string | number; field: string; value: unknown }[];
|
|
155
|
+
}): Promise<{ revision: string | number }>;
|
|
156
|
+
query(request: TableQuery): Promise<TablePage>;
|
|
157
|
+
/** With `selection`, export only those records of the result, in the same order. */
|
|
158
|
+
exportResults?(request: { state: TableState; format: TableFormat; signal?: AbortSignal; selection?: TableSelection }): Promise<Blob>;
|
|
159
|
+
detail?(request: { id: string | number; state: TableState; signal: AbortSignal }): Promise<{ field: string; value: string }[]>;
|
|
160
|
+
formats?: TableFormat[];
|
|
161
|
+
/** Set when exportResults honours `selection`; the export dialog then offers "Selected records". */
|
|
162
|
+
selectionExport?: boolean;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Selected records. `all: true` means every record matching the current filters and search except the
|
|
167
|
+
* listed ones, so selecting a large result stores nothing per record. It follows later filter changes.
|
|
168
|
+
*/
|
|
169
|
+
export type TableSelection = { all: false; ids: TableRecordId[] } | { all: true; except: TableRecordId[] };
|
|
170
|
+
|
|
171
|
+
/** The record a detail panel is built for: display text and raw values of the columns on screen. */
|
|
172
|
+
export interface TableDetailRecord {
|
|
173
|
+
id: TableRecordId;
|
|
174
|
+
values: Record<string, string>;
|
|
175
|
+
/** Numbers for number and date columns; every value in an editable local copy; otherwise null. */
|
|
176
|
+
raw: Record<string, unknown>;
|
|
177
|
+
}
|
|
178
|
+
export type TableChrome = 'auto' | 'light' | 'dark' | 'white' | 'light-gray' | 'dark-gray' | 'colorful' | 'black' | 'slate' | {base?: 'light' | 'dark'; tokens?: Record<string, string>};
|
|
179
|
+
/** Options of mountTable. Those marked "live" can change later through setOptions(). */
|
|
180
|
+
export interface TableOptions {
|
|
181
|
+
/** Theme: a named skin or custom tokens. Default 'auto' (follows the system). Live. */
|
|
182
|
+
chrome?: TableChrome;
|
|
183
|
+
/** Local records: objects, rows (the first row holds the field names when `fields` is left out) or columns. */
|
|
184
|
+
data?: Record<string, unknown>[] | unknown[][] | Record<string, ArrayLike<unknown>>;
|
|
185
|
+
/** Fields of `data` or of a `dataSource`. Inferred from `data` when left out; required with a `dataSource`. */
|
|
186
|
+
fields?: TableField[];
|
|
187
|
+
/** A CSV or Excel file to open. */
|
|
188
|
+
file?: File;
|
|
189
|
+
/** Title of the records. Default 'Table'. Live. */
|
|
190
|
+
title?: string;
|
|
191
|
+
/** Turns on saved views for `data` and `dataSource` records, stored in localStorage under this key. Live. */
|
|
192
|
+
storageKey?: string;
|
|
193
|
+
/** Interface language, 'en' or 'pl'. Default: the browser's. Live. */
|
|
194
|
+
language?: string;
|
|
195
|
+
/** Makes `data` records editable (with `dataSource`, needs its `update`). Default false. */
|
|
196
|
+
editable?: boolean;
|
|
197
|
+
/** Shows an Edit copy button for read-only local records, and lets enableEditing() make the copy. Default false. Live. */
|
|
198
|
+
allowEdit?: boolean;
|
|
199
|
+
/** 'continuous' scrolls through every record; 'pages' shows 50 at a time. Default 'continuous'. Live. */
|
|
200
|
+
scrolling?: 'continuous' | 'pages';
|
|
201
|
+
/** Records from your server, in blocks. See remoteTableSource(). */
|
|
202
|
+
dataSource?: TableDataSource;
|
|
203
|
+
/** Hands the buffers of typed-array columns in `data` to the grid's Worker instead of copying them. Default false. */
|
|
204
|
+
transferColumns?: boolean;
|
|
205
|
+
/** Draws cells of a field: return a Node or text. Live. */
|
|
206
|
+
renderers?: Record<string, (cell: { id: string | number; field: string; text: string }) => Node | string>;
|
|
207
|
+
/** Publishes a filtered copy for the Share dialog and createShareLink(). Live. */
|
|
208
|
+
sharing?: { create(file: Blob): Promise<{ id: string; url: string }>; revoke(id: string): Promise<void> };
|
|
209
|
+
/** Adds a checkbox to each record. 'multiple' also adds a header checkbox that selects every matching record. Live. */
|
|
210
|
+
rowSelection?: 'multiple' | 'single';
|
|
211
|
+
/**
|
|
212
|
+
* Builds the panel shown under a record when its row is expanded. One record is expanded at a time; the
|
|
213
|
+
* panel is built once per expansion, kept while it is open and scrolls with the records (up to 360 px tall). Live.
|
|
214
|
+
*/
|
|
215
|
+
detailRenderer?: (record: TableDetailRecord) => Node | string;
|
|
216
|
+
|
|
217
|
+
// Event handlers: the same events as grid.on(name, handler). Each is live (setOptions({ onX })).
|
|
218
|
+
/** After the view state changed: sort, filters, search, groups, columns, totals. */
|
|
219
|
+
onStateChange?: (event: TableStateChangeEvent) => void;
|
|
220
|
+
/** After a data change: an edit, paste, fill down, added or removed records, undo, redo or a calculated field. */
|
|
221
|
+
onChange?: (change: TableChange) => void;
|
|
222
|
+
/** After each row selection change. `count` is the number of selected records among the matching ones, when known. */
|
|
223
|
+
onSelectionChange?: (selection: TableSelection & { count?: number }) => void;
|
|
224
|
+
/** After the cell range changed; null when it was cleared. */
|
|
225
|
+
onRangeChange?: (range: TableRange | null) => void;
|
|
226
|
+
onCellClick?: (event: TableCellEvent) => void;
|
|
227
|
+
/** Cancellable: preventDefault() keeps the grid from editing the cell or opening the record's details. */
|
|
228
|
+
onCellDoubleClick?: (event: TableCellEvent & TableCancellable) => void;
|
|
229
|
+
onRowClick?: (event: TableRowEvent) => void;
|
|
230
|
+
/** Cancellable, as onCellDoubleClick. */
|
|
231
|
+
onRowDoubleClick?: (event: TableRowEvent & TableCancellable) => void;
|
|
232
|
+
/** Cancellable: preventDefault() keeps the cell editor closed. */
|
|
233
|
+
onEditStart?: (event: TableEditStartEvent & TableCancellable) => void | boolean;
|
|
234
|
+
onEditEnd?: (event: TableEditEndEvent) => void;
|
|
235
|
+
/** Cancellable. A handler may also change `cells[i].value` to store another value. */
|
|
236
|
+
onBeforeEdit?: (event: TableBeforeEditEvent) => void | boolean;
|
|
237
|
+
onBeforeAdd?: (event: TableBeforeAddEvent) => void | boolean;
|
|
238
|
+
onBeforeRemove?: (event: TableBeforeRemoveEvent) => void | boolean;
|
|
239
|
+
onBeforePaste?: (event: TableBeforePasteEvent) => void | boolean;
|
|
240
|
+
/** After records loaded: at mount, openFile, setData, setDataSource, setSource, openPivot and closePivot. */
|
|
241
|
+
onSourceLoad?: (event: TableSourceLoadEvent) => void;
|
|
242
|
+
/** After the rows in view or the scroll position changed. */
|
|
243
|
+
onViewportChange?: (viewport: TableViewport) => void;
|
|
244
|
+
/** A slow load began. The loading panel shows if it takes longer than 150 ms. */
|
|
245
|
+
onLoadStart?: (event: TableLoadStartEvent) => void;
|
|
246
|
+
/** Progress of the load, at most ten times a second. */
|
|
247
|
+
onLoadProgress?: (event: TableLoadProgressEvent) => void;
|
|
248
|
+
/** The load ended: done, cancelled (Cancel, cancelLoad() or a newer load) or failed. */
|
|
249
|
+
onLoadEnd?: (event: TableLoadEndEvent) => void;
|
|
250
|
+
/** An action of the interface or a remote block request failed. The grid also shows the message in its status line. */
|
|
251
|
+
onError?: (error: Error) => void;
|
|
252
|
+
}
|
|
253
|
+
export type TableRecordId = string | number;
|
|
254
|
+
export type TableCellChange = { id: TableRecordId; field: string; value: unknown };
|
|
255
|
+
/** Who made a change: the user in the grid, or the host through the API. */
|
|
256
|
+
export type TableChangeSource = 'user' | 'api';
|
|
257
|
+
/**
|
|
258
|
+
* A data change. Local sources report the operation; remote sources report the cells sent to `update`.
|
|
259
|
+
* `ids` of 'add' are the IDs the new records got, in the order of `records`.
|
|
260
|
+
*/
|
|
261
|
+
export type TableChange = (
|
|
262
|
+
| { action: 'edit'; revision?: string | number; cells: TableCellChange[] }
|
|
263
|
+
| { action: 'paste'; id: TableRecordId; field: string; lines: string[][]; repeat: number }
|
|
264
|
+
| { action: 'paste'; cells: TableCellChange[]; revision?: string | number }
|
|
265
|
+
| { action: 'add'; records: Record<string, unknown>[]; ids: TableRecordId[] }
|
|
266
|
+
| { action: 'remove'; ids: TableRecordId[] }
|
|
267
|
+
| { action: 'undo' | 'redo' }
|
|
268
|
+
| { action: 'formula'; name: string; formula: string }
|
|
269
|
+
) & { source: TableChangeSource };
|
|
270
|
+
|
|
271
|
+
/** What a cancellable event payload carries. A handler can also return false. */
|
|
272
|
+
export interface TableCancellable {
|
|
273
|
+
preventDefault(): void;
|
|
274
|
+
readonly defaultPrevented: boolean;
|
|
275
|
+
}
|
|
276
|
+
export interface TableStateChangeEvent {
|
|
277
|
+
state: TableState;
|
|
278
|
+
/** The keys of the state that changed. */
|
|
279
|
+
changed: (keyof TableState)[];
|
|
280
|
+
}
|
|
281
|
+
/** A cell range in record IDs and fields, over drawn records. `values` are display text, by record then field. */
|
|
282
|
+
export interface TableRange {
|
|
283
|
+
anchor: { id: TableRecordId; field: string };
|
|
284
|
+
focus: { id: TableRecordId; field: string };
|
|
285
|
+
ids: TableRecordId[];
|
|
286
|
+
fields: string[];
|
|
287
|
+
values: string[][];
|
|
288
|
+
}
|
|
289
|
+
export interface TableCellEvent {
|
|
290
|
+
id: TableRecordId;
|
|
291
|
+
field: string;
|
|
292
|
+
/** Display text. */
|
|
293
|
+
text: string;
|
|
294
|
+
/** Number for number and date columns (and every value in an editable copy), otherwise null. */
|
|
295
|
+
value: unknown;
|
|
296
|
+
event: MouseEvent;
|
|
297
|
+
}
|
|
298
|
+
export interface TableRowEvent {
|
|
299
|
+
id: TableRecordId;
|
|
300
|
+
/** The field of the cell clicked, or null outside the data cells. */
|
|
301
|
+
field: string | null;
|
|
302
|
+
event: MouseEvent;
|
|
303
|
+
}
|
|
304
|
+
export interface TableEditStartEvent {
|
|
305
|
+
id: TableRecordId;
|
|
306
|
+
field: string;
|
|
307
|
+
value: unknown;
|
|
308
|
+
/** The text the editor starts with. */
|
|
309
|
+
text: string;
|
|
310
|
+
}
|
|
311
|
+
export interface TableEditEndEvent {
|
|
312
|
+
id: TableRecordId;
|
|
313
|
+
field: string;
|
|
314
|
+
/** True when the editor closed without saving (Escape, stopEdit({ cancel: true }), a cancelled beforeEdit, a redraw). */
|
|
315
|
+
cancelled: boolean;
|
|
316
|
+
/** The saved value, or the old one when cancelled. */
|
|
317
|
+
value: unknown;
|
|
318
|
+
}
|
|
319
|
+
export interface TableBeforeEditEvent extends TableCancellable {
|
|
320
|
+
cells: TableCellChange[];
|
|
321
|
+
revision?: string | number;
|
|
322
|
+
source: TableChangeSource;
|
|
323
|
+
}
|
|
324
|
+
export interface TableBeforeAddEvent extends TableCancellable {
|
|
325
|
+
records: Record<string, unknown>[];
|
|
326
|
+
source: TableChangeSource;
|
|
327
|
+
}
|
|
328
|
+
export interface TableBeforeRemoveEvent extends TableCancellable {
|
|
329
|
+
ids: TableRecordId[];
|
|
330
|
+
source: TableChangeSource;
|
|
331
|
+
}
|
|
332
|
+
export interface TableBeforePasteEvent extends TableCancellable {
|
|
333
|
+
id: TableRecordId;
|
|
334
|
+
field: string;
|
|
335
|
+
lines: string[][];
|
|
336
|
+
repeat: number;
|
|
337
|
+
source: TableChangeSource;
|
|
338
|
+
}
|
|
339
|
+
export type TableSourceKind = 'file' | 'data' | 'remote' | 'pivot';
|
|
340
|
+
export interface TableSourceLoadEvent {
|
|
341
|
+
kind: TableSourceKind;
|
|
342
|
+
title: string;
|
|
343
|
+
fields: TableFieldInfo[];
|
|
344
|
+
}
|
|
345
|
+
/** View rows in the scroll area. A view row is a record or a group row; with groups the indexes count both. */
|
|
346
|
+
export interface TableViewport {
|
|
347
|
+
firstRow: number;
|
|
348
|
+
lastRow: number;
|
|
349
|
+
/** Rows of the result. While `exact` is false, a remote source hasn't reported its total yet. */
|
|
350
|
+
rowCount: number;
|
|
351
|
+
exact: boolean;
|
|
352
|
+
scrollTop: number;
|
|
353
|
+
scrollLeft: number;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* What a load does: 'file' (openFile, CSV reimport), 'source' (setSource), 'data' (setData, packing large
|
|
357
|
+
* arrays), 'remote' (a remote source's first block), 'pivot' (openPivot) or a name a host passes, such as the
|
|
358
|
+
* examples' 'generate'.
|
|
359
|
+
*/
|
|
360
|
+
export type TableLoadTask = 'file' | 'source' | 'data' | 'remote' | 'pivot' | (string & {});
|
|
361
|
+
export interface TableLoadStartEvent {
|
|
362
|
+
task: TableLoadTask;
|
|
363
|
+
/** What the panel says, e.g. "Opening sales.csv", in the grid's language. */
|
|
364
|
+
label: string;
|
|
365
|
+
}
|
|
366
|
+
export interface TableLoadProgressEvent {
|
|
367
|
+
task: TableLoadTask;
|
|
368
|
+
/** Records read or prepared so far, or null when unknown. */
|
|
369
|
+
records: number | null;
|
|
370
|
+
/** Progress units done: bytes for CSV, cells for XLSX, records when packing. Null when unknown. */
|
|
371
|
+
loaded: number | null;
|
|
372
|
+
/** The units in all, or null when unknown (the bar is then indeterminate). XLSX totals come from the sheets' dimensions. */
|
|
373
|
+
total: number | null;
|
|
374
|
+
/** loaded / total, from 0 to 1, or null. */
|
|
375
|
+
fraction: number | null;
|
|
376
|
+
}
|
|
377
|
+
export interface TableLoadEndEvent {
|
|
378
|
+
task: TableLoadTask;
|
|
379
|
+
label: string;
|
|
380
|
+
status: 'done' | 'cancelled' | 'failed';
|
|
381
|
+
error?: Error;
|
|
382
|
+
/** Matching records after a load that is done, when known. */
|
|
383
|
+
records: number | null;
|
|
384
|
+
/** Milliseconds from the start. */
|
|
385
|
+
duration: number;
|
|
386
|
+
}
|
|
387
|
+
/** The events of grid.on(); each has an `on…` option of the same name (stateChange is onStateChange). */
|
|
388
|
+
export interface TableEventMap {
|
|
389
|
+
stateChange: TableStateChangeEvent;
|
|
390
|
+
change: TableChange;
|
|
391
|
+
selectionChange: TableSelection & { count?: number };
|
|
392
|
+
rangeChange: TableRange | null;
|
|
393
|
+
cellClick: TableCellEvent;
|
|
394
|
+
cellDoubleClick: TableCellEvent & TableCancellable;
|
|
395
|
+
rowClick: TableRowEvent;
|
|
396
|
+
rowDoubleClick: TableRowEvent & TableCancellable;
|
|
397
|
+
editStart: TableEditStartEvent & TableCancellable;
|
|
398
|
+
editEnd: TableEditEndEvent;
|
|
399
|
+
beforeEdit: TableBeforeEditEvent;
|
|
400
|
+
beforeAdd: TableBeforeAddEvent;
|
|
401
|
+
beforeRemove: TableBeforeRemoveEvent;
|
|
402
|
+
beforePaste: TableBeforePasteEvent;
|
|
403
|
+
sourceLoad: TableSourceLoadEvent;
|
|
404
|
+
viewportChange: TableViewport;
|
|
405
|
+
loadStart: TableLoadStartEvent;
|
|
406
|
+
loadProgress: TableLoadProgressEvent;
|
|
407
|
+
loadEnd: TableLoadEndEvent;
|
|
408
|
+
error: Error;
|
|
409
|
+
}
|
|
410
|
+
export type TableEventName = keyof TableEventMap;
|
|
411
|
+
|
|
412
|
+
/** A source of an open file: a sheet (`whole`, its range and header row can be chosen) or a table. */
|
|
413
|
+
export interface TableFileSource {
|
|
414
|
+
index: number;
|
|
415
|
+
name: string;
|
|
416
|
+
/** Its used range, e.g. 'A1:F61'. */
|
|
417
|
+
range: string;
|
|
418
|
+
whole: boolean;
|
|
419
|
+
header: boolean;
|
|
420
|
+
}
|
|
421
|
+
/** What the grid shows. `index`, `range` and `header` are set for a file. */
|
|
422
|
+
export interface TableSourceInfo {
|
|
423
|
+
kind: TableSourceKind | 'none';
|
|
424
|
+
title: string;
|
|
425
|
+
/** Whether edits are accepted now. */
|
|
426
|
+
editable: boolean;
|
|
427
|
+
/** Whether local records were changed since they were opened. */
|
|
428
|
+
dirty: boolean;
|
|
429
|
+
fileName?: string;
|
|
430
|
+
index?: number;
|
|
431
|
+
range?: string;
|
|
432
|
+
header?: boolean;
|
|
433
|
+
}
|
|
434
|
+
/** A record read through the API: display text and value of each field. */
|
|
435
|
+
export interface TableRecord {
|
|
436
|
+
id: TableRecordId;
|
|
437
|
+
values: Record<string, string>;
|
|
438
|
+
/** Numbers (dates as serial numbers), text, booleans or null; an error value is its code. Empty for remote details. */
|
|
439
|
+
raw: Record<string, unknown>;
|
|
440
|
+
}
|
|
441
|
+
export interface TableCounts {
|
|
442
|
+
/** Matching records; null while a remote source hasn't reported them. */
|
|
443
|
+
matches: number | null;
|
|
444
|
+
/** Records before filtering; null when unknown. */
|
|
445
|
+
sourceCount: number | null;
|
|
446
|
+
/** Rows of the result, group rows included. */
|
|
447
|
+
count: number;
|
|
448
|
+
exact: boolean;
|
|
449
|
+
}
|
|
450
|
+
export interface TableTotals {
|
|
451
|
+
/** The summary (state.total) over every matching record, as display text. */
|
|
452
|
+
summary: (TableSummary & { text: string }) | null;
|
|
453
|
+
/** The totals row's display text per field, for the columns on the drawn column page. */
|
|
454
|
+
totals: Record<string, string>;
|
|
455
|
+
}
|
|
456
|
+
export interface TablePivot {
|
|
457
|
+
rowField: string;
|
|
458
|
+
/** A field whose values become columns. Default none. */
|
|
459
|
+
columnField?: string;
|
|
460
|
+
valueField: string;
|
|
461
|
+
/** Default 'sum'. */
|
|
462
|
+
agg?: 'sum' | 'average' | 'min' | 'max' | 'count';
|
|
463
|
+
}
|
|
464
|
+
export type TableDialog =
|
|
465
|
+
| 'filter'
|
|
466
|
+
| 'sort'
|
|
467
|
+
| 'group'
|
|
468
|
+
| 'summary'
|
|
469
|
+
| 'columns'
|
|
470
|
+
| 'views'
|
|
471
|
+
| 'pivot'
|
|
472
|
+
| 'chart'
|
|
473
|
+
| 'export'
|
|
474
|
+
| 'share'
|
|
475
|
+
| 'calculatedField'
|
|
476
|
+
| 'addRecord'
|
|
477
|
+
| 'source'
|
|
478
|
+
| 'conditionalFormatting';
|
|
479
|
+
/** A group, by its values from the top level down (`['East', 'Widget']`), or by the path a state lists. */
|
|
480
|
+
export type TableGroupRef = unknown[] | string;
|
|
481
|
+
/** Options setOptions() can change after mount, and `on…` handlers (null removes one). */
|
|
482
|
+
export type TableLiveOptions = Partial<
|
|
483
|
+
Pick<TableOptions, 'chrome' | 'language' | 'title' | 'scrolling' | 'rowSelection' | 'renderers' | 'detailRenderer' | 'allowEdit' | 'sharing' | 'storageKey'>
|
|
484
|
+
> & { [handler: `on${string}`]: ((...args: any[]) => any) | null | undefined };
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* A mounted grid. Everything a user can do in the grid, the host can do here; the interface takes the same
|
|
488
|
+
* paths, so the same events fire either way. Methods that change the view resolve once it is drawn again.
|
|
489
|
+
* Methods that need records throw "No table loaded." before any are, and every method throws after destroy().
|
|
490
|
+
*/
|
|
491
|
+
export interface MountedTable {
|
|
492
|
+
// ---- Events ----
|
|
493
|
+
/**
|
|
494
|
+
* Adds an event handler; returns a function that removes it. The `on…` option of the event runs first.
|
|
495
|
+
* @example const stop = grid.on('stateChange', (e) => save(e.state));
|
|
496
|
+
*/
|
|
497
|
+
on<K extends TableEventName>(type: K, handler: (event: TableEventMap[K]) => void | boolean): () => void;
|
|
498
|
+
/** Removes a handler added with on(). @example grid.off('change', onChange); */
|
|
499
|
+
off<K extends TableEventName>(type: K, handler: (event: TableEventMap[K]) => void | boolean): void;
|
|
500
|
+
|
|
501
|
+
// ---- Lifecycle and sources ----
|
|
502
|
+
/** Removes the grid and ends its Worker and requests. @example grid.destroy(); */
|
|
503
|
+
destroy(): void;
|
|
504
|
+
/**
|
|
505
|
+
* Opens a CSV or Excel file in place of the records. `textColumns` reads CSV columns as text ('A' or 0).
|
|
506
|
+
* With `chooseSource` (default true) a file with several sheets or tables shows the source chooser.
|
|
507
|
+
* @example await grid.openFile(file, { delimiter: ';', chooseSource: false });
|
|
508
|
+
*/
|
|
509
|
+
openFile(file: File, options?: { delimiter?: string; textColumns?: (string | number)[]; chooseSource?: boolean }): Promise<void>;
|
|
510
|
+
/**
|
|
511
|
+
* Shows other local records. Options left out keep their mount values. The view starts over.
|
|
512
|
+
* @example await grid.setData(rows, { fields, title: 'Orders', editable: true });
|
|
513
|
+
*/
|
|
514
|
+
setData(data: NonNullable<TableOptions['data']>, options?: { fields?: TableField[]; title?: string; editable?: boolean; storageKey?: string }): Promise<void>;
|
|
515
|
+
/**
|
|
516
|
+
* Shows records from another data source. `fields` is required unless given at mount.
|
|
517
|
+
* @example await grid.setDataSource(remoteTableSource({ queryUrl: '/api/orders' }), { fields });
|
|
518
|
+
*/
|
|
519
|
+
setDataSource(dataSource: TableDataSource, options?: { fields?: TableField[]; title?: string; editable?: boolean; storageKey?: string }): Promise<void>;
|
|
520
|
+
/** The sheets and tables of the open file; empty for other sources. @example grid.getSources()[1].name */
|
|
521
|
+
getSources(): TableFileSource[];
|
|
522
|
+
/**
|
|
523
|
+
* Shows another sheet or table of the open file. For a sheet, `range` (inside its used range) and `header`
|
|
524
|
+
* (default true: the first row holds the field names) choose the records.
|
|
525
|
+
* @example await grid.setSource(0, { range: 'A1:D40', header: true });
|
|
526
|
+
*/
|
|
527
|
+
setSource(index: number, options?: { range?: string; header?: boolean }): Promise<void>;
|
|
528
|
+
/** What the grid shows. @example if (grid.getSource().dirty) warn(); */
|
|
529
|
+
getSource(): TableSourceInfo;
|
|
530
|
+
/**
|
|
531
|
+
* Draws the records again. For a remote source it fetches them again; `purge` (default false) also forgets
|
|
532
|
+
* the known total, as for a new query.
|
|
533
|
+
* @example await grid.refresh();
|
|
534
|
+
*/
|
|
535
|
+
refresh(options?: { purge?: boolean }): Promise<void>;
|
|
536
|
+
|
|
537
|
+
// ---- View state ----
|
|
538
|
+
/** A copy of the view state. @example localStorage.view = JSON.stringify(grid.getState()); */
|
|
539
|
+
getState(): TableState;
|
|
540
|
+
/** Replaces the whole view state; keys left out take their defaults. Scrolls to the top. @example await grid.setState(saved); */
|
|
541
|
+
setState(state: Partial<TableState>): Promise<void>;
|
|
542
|
+
/** Changes some keys of the view state. Scrolls to the top. @example await grid.updateState({ search: 'east', sort: [] }); */
|
|
543
|
+
updateState(patch: Partial<TableState>): Promise<void>;
|
|
544
|
+
/** The view of a fresh source: every field in order, nothing filtered, sorted or grouped. @example await grid.resetState(); */
|
|
545
|
+
resetState(): Promise<void>;
|
|
546
|
+
/** Searches every visible field. '' clears it. @example await grid.setSearch('east'); */
|
|
547
|
+
setSearch(text: string): Promise<void>;
|
|
548
|
+
/** Replaces the filters. @example await grid.setFilters([{ field: 'Units', op: 'gt', value: 10 }]); */
|
|
549
|
+
setFilters(filters: TableFilter[]): Promise<void>;
|
|
550
|
+
/** Adds a filter; filters combine with AND. @example await grid.addFilter({ field: 'Region', op: 'in', values: ['East', 'West'] }); */
|
|
551
|
+
addFilter(filter: TableFilter): Promise<void>;
|
|
552
|
+
/** Removes every filter, or those of one field. The search stays. @example await grid.clearFilters('Region'); */
|
|
553
|
+
clearFilters(field?: string): Promise<void>;
|
|
554
|
+
/**
|
|
555
|
+
* Sets a field's filter-row filter from typed text: '>100', '<=5', '10..20', '=42' for numbers and dates,
|
|
556
|
+
* words or '=word' for text. '' removes it. Works with the filter row shown or hidden.
|
|
557
|
+
* @example await grid.setQuickFilter('Units', '>30');
|
|
558
|
+
*/
|
|
559
|
+
setQuickFilter(field: string, text: string): Promise<void>;
|
|
560
|
+
/**
|
|
561
|
+
* A field's values among the records the other filters let through, with counts (as Pick values lists).
|
|
562
|
+
* Local records only. `limit` default 500.
|
|
563
|
+
* @example const regions = await grid.getDistinctValues('Region');
|
|
564
|
+
*/
|
|
565
|
+
getDistinctValues(field: string, options?: { limit?: number }): Promise<{ value: unknown; text: string; count: number }[]>;
|
|
566
|
+
/** Replaces the sort keys. @example await grid.setSort([{ field: 'Region' }, { field: 'Units', desc: true }]); */
|
|
567
|
+
setSort(sort: TableSortKey[]): Promise<void>;
|
|
568
|
+
/**
|
|
569
|
+
* Sorts by a field alone (as clicking its heading), or with `add: true` keeps the other keys (as
|
|
570
|
+
* Shift-click). `desc` default false.
|
|
571
|
+
* @example await grid.sortBy('Revenue', { desc: true, add: true });
|
|
572
|
+
*/
|
|
573
|
+
sortBy(field: string, options?: { desc?: boolean; add?: boolean }): Promise<void>;
|
|
574
|
+
/** Removes every sort key, or one field's. @example await grid.clearSort(); */
|
|
575
|
+
clearSort(field?: string): Promise<void>;
|
|
576
|
+
/** Replaces the groups, outermost first. @example await grid.setGroups([{ field: 'Region' }, { field: 'Product' }]); */
|
|
577
|
+
setGroups(groups: TableGroup[]): Promise<void>;
|
|
578
|
+
/** Adds a group level under the others. @example await grid.groupBy('Region'); */
|
|
579
|
+
groupBy(field: string, options?: { desc?: boolean }): Promise<void>;
|
|
580
|
+
/** Removes every group level, or one field's. @example await grid.clearGroups('Region'); */
|
|
581
|
+
clearGroups(field?: string): Promise<void>;
|
|
582
|
+
/** Expands a group. @example await grid.expandGroup(['East', 'Widget']); */
|
|
583
|
+
expandGroup(group: TableGroupRef): Promise<void>;
|
|
584
|
+
/** Collapses a group. @example await grid.collapseGroup(['East']); */
|
|
585
|
+
collapseGroup(group: TableGroupRef): Promise<void>;
|
|
586
|
+
/** Expands every group. @example await grid.expandAll(); */
|
|
587
|
+
expandAll(): Promise<void>;
|
|
588
|
+
/** Collapses every group, at every level. @example await grid.collapseAll(); */
|
|
589
|
+
collapseAll(): Promise<void>;
|
|
590
|
+
/** Sets the summary under the records and in each group row, or null for none. @example await grid.setSummary({ field: 'Revenue', agg: 'sum' }); */
|
|
591
|
+
setSummary(summary: TableSummary | null): Promise<void>;
|
|
592
|
+
/** Shows or hides the totals row. Turning it on sums each number column that has no total yet. @example await grid.setTotalsRow(true); */
|
|
593
|
+
setTotalsRow(on: boolean): Promise<void>;
|
|
594
|
+
/** Shows or hides the filter row under the headings. Its filters stay either way. @example await grid.setFilterRow(true); */
|
|
595
|
+
setFilterRow(on: boolean): Promise<void>;
|
|
596
|
+
|
|
597
|
+
// ---- Columns ----
|
|
598
|
+
/** The fields of the records. @example grid.getFields().map((f) => f.name) */
|
|
599
|
+
getFields(): TableFieldInfo[];
|
|
600
|
+
/** A copy of one column's settings, or null. @example grid.getColumn('Units')?.width */
|
|
601
|
+
getColumn(field: string): TableColumnState | null;
|
|
602
|
+
/** Replaces the columns: order, visibility, pins, widths, formats, totals and rules. @example await grid.setColumns(grid.getState().columns.reverse()); */
|
|
603
|
+
setColumns(columns: TableColumnState[]): Promise<void>;
|
|
604
|
+
/**
|
|
605
|
+
* Changes some settings of a column: hide or show, pin, width (48 to 800 px, null for automatic), number
|
|
606
|
+
* format, totals-row aggregate (null for none) and conditional rules. The scroll position stays.
|
|
607
|
+
* @example await grid.setColumn('Revenue', { pinned: true, width: 140, format: '#,##0.00', total: 'sum' });
|
|
608
|
+
*/
|
|
609
|
+
setColumn(field: string, patch: Partial<Omit<TableColumnState, 'field'>>): Promise<void>;
|
|
610
|
+
/** Moves a column before another one, or to the end. @example await grid.moveColumn('Revenue', 'Units'); */
|
|
611
|
+
moveColumn(field: string, before?: string | null): Promise<void>;
|
|
612
|
+
/** Fits a column to its heading and loaded values; resolves with the width, or null. @example await grid.autosizeColumn('Customer'); */
|
|
613
|
+
autosizeColumn(field: string): Promise<number | null>;
|
|
614
|
+
/**
|
|
615
|
+
* Adds a field computed from each record to an editable local copy, and shows it.
|
|
616
|
+
* @example await grid.addCalculatedField('Total', '=[@Units]*[@Price]');
|
|
617
|
+
*/
|
|
618
|
+
addCalculatedField(name: string, formula: string): Promise<void>;
|
|
619
|
+
|
|
620
|
+
// ---- Saved views (need a storageKey for data and remote sources; files have one) ----
|
|
621
|
+
/** The saved views, in the order saved. @example grid.getSavedViews().map((v) => v.name) */
|
|
622
|
+
getSavedViews(): { name: string; state: TableState }[];
|
|
623
|
+
/** Saves the current view (or `state`) under a name, replacing one of that name. @example grid.saveView('East only'); */
|
|
624
|
+
saveView(name: string, state?: TableState): void;
|
|
625
|
+
/** Shows a saved view. @example await grid.restoreView('East only'); */
|
|
626
|
+
restoreView(name: string): Promise<void>;
|
|
627
|
+
/** Deletes a saved view; false when there was none. @example grid.deleteView('East only'); */
|
|
628
|
+
deleteView(name: string): boolean;
|
|
629
|
+
|
|
630
|
+
// ---- Pivot and chart (local records) ----
|
|
631
|
+
/**
|
|
632
|
+
* Replaces the records with a pivot of the matching ones. closePivot() returns to them and their view.
|
|
633
|
+
* @example await grid.openPivot({ rowField: 'Region', columnField: 'Product', valueField: 'Revenue' });
|
|
634
|
+
*/
|
|
635
|
+
openPivot(pivot: TablePivot): Promise<void>;
|
|
636
|
+
/** Leaves a pivot for the records. Nothing happens outside a pivot. @example await grid.closePivot(); */
|
|
637
|
+
closePivot(): Promise<void>;
|
|
638
|
+
/** The pivot's top 20 values of a field by absolute value, as the Chart dialog draws them. @example await grid.getChartData('Total'); */
|
|
639
|
+
getChartData(field: string): Promise<{ label: string; value: number; text: string }[]>;
|
|
640
|
+
|
|
641
|
+
// ---- Paging, scrolling and focus ----
|
|
642
|
+
/** The page shown in 'pages' mode. `count` is null while a remote total is unknown. @example grid.getPage().index */
|
|
643
|
+
getPage(): { mode: 'continuous' | 'pages'; index: number; count: number | null; size: number | null };
|
|
644
|
+
/** Shows a page, from 0, in 'pages' mode. @example await grid.setPage(2); */
|
|
645
|
+
setPage(index: number): Promise<void>;
|
|
646
|
+
/** Switches between continuous scrolling and pages. @example await grid.setScrolling('pages'); */
|
|
647
|
+
setScrolling(mode: 'continuous' | 'pages'): Promise<void>;
|
|
648
|
+
/** The view rows in the scroll area. @example const { firstRow, lastRow } = grid.getViewport(); */
|
|
649
|
+
getViewport(): TableViewport;
|
|
650
|
+
/** Scrolls a view row (a record or group row, from 0) into view. A remote row may still be loading. @example await grid.scrollToRow(5000); */
|
|
651
|
+
scrollToRow(index: number): Promise<void>;
|
|
652
|
+
/**
|
|
653
|
+
* Scrolls a record into view; false when it doesn't match or sits in a collapsed group. A remote source
|
|
654
|
+
* scrolls to loaded records only and rejects others.
|
|
655
|
+
* @example await grid.scrollToRecord(42);
|
|
656
|
+
*/
|
|
657
|
+
scrollToRecord(id: TableRecordId): Promise<boolean>;
|
|
658
|
+
/** Scrolls a visible column into view. @example await grid.scrollToColumn('Revenue'); */
|
|
659
|
+
scrollToColumn(field: string): Promise<void>;
|
|
660
|
+
/** Scrolls to a cell and gives it keyboard focus; false as scrollToRecord. @example await grid.focusCell(42, 'Units'); */
|
|
661
|
+
focusCell(id: TableRecordId, field: string): Promise<boolean>;
|
|
662
|
+
/** The cell with keyboard focus, or null. @example grid.getFocusedCell()?.field */
|
|
663
|
+
getFocusedCell(): { id: TableRecordId; field: string } | null;
|
|
664
|
+
|
|
665
|
+
// ---- Cell range (over drawn records) ----
|
|
666
|
+
/** The selected cells, or null. @example grid.getRange()?.values */
|
|
667
|
+
getRange(): TableRange | null;
|
|
668
|
+
/**
|
|
669
|
+
* Selects cells from `anchor` to `focus` (default the anchor). It scrolls to the anchor when needed; both
|
|
670
|
+
* ends must then be drawn, which a range of up to a screenful of records is.
|
|
671
|
+
* @example await grid.setRange({ anchor: { id: 0, field: 'Units' }, focus: { id: 4, field: 'Price' } });
|
|
672
|
+
*/
|
|
673
|
+
setRange(range: { anchor: { id: TableRecordId; field: string }; focus?: { id: TableRecordId; field: string } }): Promise<void>;
|
|
674
|
+
/** Copies the range as tab-separated text (as Ctrl+C) and resolves with it. Needs clipboard permission. @example await grid.copyRange(); */
|
|
675
|
+
copyRange(): Promise<string>;
|
|
676
|
+
|
|
677
|
+
// ---- Row selection (needs rowSelection) ----
|
|
678
|
+
/** The selected records. @example const sel = grid.getSelection(); */
|
|
679
|
+
getSelection(): TableSelection;
|
|
680
|
+
/** Replaces the selection. @example await grid.setSelection({ all: false, ids: [1, 2] }); */
|
|
681
|
+
setSelection(selection: TableSelection): Promise<void>;
|
|
682
|
+
/** Selects (or with `selected: false` clears) some records, keeping the others. @example await grid.selectRecords([7, 9]); */
|
|
683
|
+
selectRecords(ids: TableRecordId[], selected?: boolean): Promise<void>;
|
|
684
|
+
/** Selects every matching record. @example await grid.selectAll(); */
|
|
685
|
+
selectAll(): Promise<void>;
|
|
686
|
+
/** Clears the selection. @example await grid.clearSelection(); */
|
|
687
|
+
clearSelection(): Promise<void>;
|
|
688
|
+
/**
|
|
689
|
+
* IDs of the selected records that match the current view, in display order. A remote source can't list
|
|
690
|
+
* "all matching records"; this rejects then, and the host resolves getSelection() on its server.
|
|
691
|
+
* @example const ids = await grid.getSelectedIds();
|
|
692
|
+
*/
|
|
693
|
+
getSelectedIds(): Promise<TableRecordId[]>;
|
|
694
|
+
|
|
695
|
+
// ---- Record details and master/detail ----
|
|
696
|
+
/** Opens a record's details dialog (where an editable record can be changed or removed). @example await grid.openRecordDetails(42); */
|
|
697
|
+
openRecordDetails(id: TableRecordId): Promise<void>;
|
|
698
|
+
/**
|
|
699
|
+
* Opens one of the grid's dialogs, as its toolbar does. `field` preselects the field of 'filter' and is
|
|
700
|
+
* required for 'conditionalFormatting'. Rejects when the dialog doesn't apply (e.g. 'chart' outside a pivot).
|
|
701
|
+
* @example await grid.openDialog('filter', { field: 'Region' });
|
|
702
|
+
*/
|
|
703
|
+
openDialog(name: TableDialog, options?: { field?: string }): Promise<void>;
|
|
704
|
+
/** Closes the open dialog or menu; false when none was open. @example grid.closeDialog(); */
|
|
705
|
+
closeDialog(): boolean;
|
|
706
|
+
/** Expands a record's detail panel (needs detailRenderer), closing any other; false as scrollToRecord. @example await grid.expandRecord(42); */
|
|
707
|
+
expandRecord(id: TableRecordId): Promise<boolean>;
|
|
708
|
+
/** Closes the detail panel; false when none was open. @example grid.collapseRecord(); */
|
|
709
|
+
collapseRecord(): boolean;
|
|
710
|
+
/** The record whose detail panel is open, or null. @example grid.getExpandedRecord() */
|
|
711
|
+
getExpandedRecord(): TableRecordId | null;
|
|
712
|
+
|
|
713
|
+
// ---- Editing ----
|
|
714
|
+
/** Whether edits are accepted now. @example grid.isEditable() */
|
|
715
|
+
isEditable(): boolean;
|
|
716
|
+
/**
|
|
717
|
+
* Makes an editable copy of read-only local records, as the Edit copy button. Needs `allowEdit` (or
|
|
718
|
+
* `editable`); rejects for a remote source and in a pivot.
|
|
719
|
+
* @example await grid.enableEditing();
|
|
720
|
+
*/
|
|
721
|
+
enableEditing(): Promise<void>;
|
|
722
|
+
/**
|
|
723
|
+
* Stores a value in a cell. Resolves with false when a beforeEdit handler cancelled it. Rejects for a
|
|
724
|
+
* read-only view, a read-only, computed or hidden field, or a value a field rule refuses.
|
|
725
|
+
* @example await grid.setCellValue(42, 'Units', 12);
|
|
726
|
+
*/
|
|
727
|
+
setCellValue(id: TableRecordId, field: string, value: unknown): Promise<boolean>;
|
|
728
|
+
/** Stores values in several records as one change and one undo step. @example await grid.updateRecords([{ id: 1, values: { Units: 3, Price: 9.5 } }]); */
|
|
729
|
+
updateRecords(updates: { id: TableRecordId; values: Record<string, unknown> }[]): Promise<boolean>;
|
|
730
|
+
/**
|
|
731
|
+
* Adds records to an editable local copy as one undo step, and resolves with their IDs (null when a
|
|
732
|
+
* beforeAdd handler cancelled it). Field rules and required fields apply to each.
|
|
733
|
+
* @example const [id] = await grid.addRecords([{ Customer: 'Acme', Units: 5 }]);
|
|
734
|
+
*/
|
|
735
|
+
addRecords(records: Record<string, unknown>[]): Promise<TableRecordId[] | null>;
|
|
736
|
+
/** Removes records from an editable local copy as one undo step. @example await grid.removeRecords([42]); */
|
|
737
|
+
removeRecords(ids: TableRecordId[]): Promise<boolean>;
|
|
738
|
+
/**
|
|
739
|
+
* Pastes tab-separated text (or rows of values) from a cell rightwards and down, over matching records in
|
|
740
|
+
* view order; `repeat` (default 1) repeats the rows. The start defaults to the range's top-left cell.
|
|
741
|
+
* @example await grid.paste('3\t9.5\n4\t10', { id: 0, field: 'Units' });
|
|
742
|
+
*/
|
|
743
|
+
paste(data: string | unknown[][], options?: { id?: TableRecordId; field?: string; repeat?: number }): Promise<boolean>;
|
|
744
|
+
/** Copies the range's first record into the records below it, as Ctrl+D. Local records. @example await grid.fillDown(); */
|
|
745
|
+
fillDown(): Promise<boolean>;
|
|
746
|
+
/** Undoes the last change of an editable local copy; false when there is none. @example await grid.undo(); */
|
|
747
|
+
undo(): Promise<boolean>;
|
|
748
|
+
/** Redoes the last undone change; false when there is none. @example await grid.redo(); */
|
|
749
|
+
redo(): Promise<boolean>;
|
|
750
|
+
/** Whether undo() has a change to undo (always false for a remote source). @example undoButton.disabled = !grid.canUndo(); */
|
|
751
|
+
canUndo(): boolean;
|
|
752
|
+
/** Whether redo() has a change to redo. @example redoButton.disabled = !grid.canRedo(); */
|
|
753
|
+
canRedo(): boolean;
|
|
754
|
+
/**
|
|
755
|
+
* Opens the cell editor on a cell, scrolling to it; `text` replaces the value, as typing does. False when
|
|
756
|
+
* the record isn't in the view or an editStart handler cancelled.
|
|
757
|
+
* @example await grid.startEdit(42, 'Units');
|
|
758
|
+
*/
|
|
759
|
+
startEdit(id: TableRecordId, field: string, options?: { text?: string }): Promise<boolean>;
|
|
760
|
+
/**
|
|
761
|
+
* Closes the cell editor: saves its value, or with `cancel` drops it. False when no editor was open or the
|
|
762
|
+
* value was refused (the editor then stays open with the reason).
|
|
763
|
+
* @example await grid.stopEdit({ cancel: true });
|
|
764
|
+
*/
|
|
765
|
+
stopEdit(options?: { cancel?: boolean }): Promise<boolean>;
|
|
766
|
+
/** The cell being edited, or null. @example grid.getEditingCell() */
|
|
767
|
+
getEditingCell(): { id: TableRecordId; field: string } | null;
|
|
768
|
+
|
|
769
|
+
// ---- Export and sharing ----
|
|
770
|
+
/** The matching records and visible columns as a file, or with `selected: true` only the selected ones among them. @example const blob = await grid.exportResults('xlsx'); */
|
|
771
|
+
exportResults(format: TableFormat, options?: { selected?: boolean }): Promise<Blob>;
|
|
772
|
+
/** Exports and saves the file through the browser. `fileName` default: the title and record count. @example await grid.download('csv', { fileName: 'orders.csv' }); */
|
|
773
|
+
download(format: TableFormat, options?: { selected?: boolean; fileName?: string }): Promise<void>;
|
|
774
|
+
/** Publishes the matching records as an XLSX copy through the `sharing` option. @example const { url } = await grid.createShareLink(); */
|
|
775
|
+
createShareLink(): Promise<{ id: string; url: string }>;
|
|
776
|
+
/** Revokes the last link createShareLink() made; false when there was none. @example await grid.revokeShareLink(); */
|
|
777
|
+
revokeShareLink(): Promise<boolean>;
|
|
778
|
+
|
|
779
|
+
// ---- Loading ----
|
|
780
|
+
/** Whether a load runs now (a file, source, records, a remote first block or a pivot). @example spinner.hidden = !grid.isLoading(); */
|
|
781
|
+
isLoading(): boolean;
|
|
782
|
+
/**
|
|
783
|
+
* Cancels the load in progress, as its Cancel button does; false when none runs or it can't be cancelled.
|
|
784
|
+
* The records shown before stay as they were, and the call that started the load rejects with an AbortError.
|
|
785
|
+
* @example grid.cancelLoad();
|
|
786
|
+
*/
|
|
787
|
+
cancelLoad(): boolean;
|
|
788
|
+
|
|
789
|
+
// ---- Appearance and options ----
|
|
790
|
+
/** Changes the theme. @example grid.setChrome('dark'); */
|
|
791
|
+
setChrome(chrome: TableChrome): void;
|
|
792
|
+
/** The theme in use. @example grid.getChrome() === 'dark' */
|
|
793
|
+
getChrome(): TableChrome;
|
|
794
|
+
/** Changes the interface language ('en', 'pl'). @example grid.setLanguage('pl'); */
|
|
795
|
+
setLanguage(language: string): void;
|
|
796
|
+
/** The interface language in use. @example grid.getLanguage() */
|
|
797
|
+
getLanguage(): string;
|
|
798
|
+
/**
|
|
799
|
+
* Changes live options and event handlers. Options that set the records (data, fields, file, dataSource,
|
|
800
|
+
* editable, transferColumns) reject: use setData(), setDataSource(), openFile() or enableEditing().
|
|
801
|
+
* @example await grid.setOptions({ rowSelection: 'multiple', onChange: save });
|
|
802
|
+
*/
|
|
803
|
+
setOptions(options: TableLiveOptions): Promise<void>;
|
|
804
|
+
|
|
805
|
+
// ---- Reading records ----
|
|
806
|
+
/**
|
|
807
|
+
* Matching records in display order (groups don't count, collapsed ones included), from `offset` (default
|
|
808
|
+
* 0), at most `limit` (default 100, up to 10000). `total` is the number of matching records, or null while
|
|
809
|
+
* a remote source hasn't reported it. A remote source is queried through its `query`; grouped, it rejects.
|
|
810
|
+
* @example const { records } = await grid.getRecords({ offset: 0, limit: 500 });
|
|
811
|
+
*/
|
|
812
|
+
getRecords(options?: { offset?: number; limit?: number }): Promise<{ total: number | null; records: TableRecord[] }>;
|
|
813
|
+
/**
|
|
814
|
+
* One record with every field. A remote record comes from the loaded rows (the columns on screen) or the
|
|
815
|
+
* source's `detail` (display text only), and otherwise rejects.
|
|
816
|
+
* @example const order = await grid.getRecord(42);
|
|
817
|
+
*/
|
|
818
|
+
getRecord(id: TableRecordId): Promise<TableRecord>;
|
|
819
|
+
/** A cell's value and display text. @example const { value, text } = await grid.getCell(42, 'Revenue'); */
|
|
820
|
+
getCell(id: TableRecordId, field: string): Promise<{ value: unknown; text: string }>;
|
|
821
|
+
/** Record and row counts of the result. @example grid.getCounts().matches */
|
|
822
|
+
getCounts(): TableCounts;
|
|
823
|
+
/** The summary and totals-row values over every matching record, as display text. @example grid.getTotals().totals.Revenue */
|
|
824
|
+
getTotals(): TableTotals;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Mounts a Data Grid into an element, which needs a height. Resolves once the first records are drawn.
|
|
828
|
+
* @example const grid = await mountTable(document.querySelector('#orders'), { data: rows, rowSelection: 'multiple' });
|
|
829
|
+
*/
|
|
830
|
+
export function mountTable(element: HTMLElement, options?: TableOptions): Promise<MountedTable>;
|
|
831
|
+
export function remoteTableSource(options: {
|
|
832
|
+
queryUrl: string;
|
|
833
|
+
exportUrl?: string;
|
|
834
|
+
detailUrl?: string;
|
|
835
|
+
updateUrl?: string;
|
|
836
|
+
headers?: HeadersInit | (() => Promise<HeadersInit>);
|
|
837
|
+
credentials?: RequestCredentials;
|
|
838
|
+
formats?: TableFormat[];
|
|
839
|
+
/** The export endpoint accepts a `selection` and exports only those records. */
|
|
840
|
+
selectionExport?: boolean;
|
|
841
|
+
}): TableDataSource;
|