Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/collections/table): add more properties

Elian Doranb62d1a303c3b
diff --git a/apps/client/src/widgets/collections/table/index.tsx b/apps/client/src/widgets/collections/table/index.tsx
index e9c8b88021..0fac94210c 100644
--- a/apps/client/src/widgets/collections/table/index.tsx
+++ b/apps/client/src/widgets/collections/table/index.tsx
@@ -23,6 +23,7 @@ export default function TableView({ note, viewConfig, saveConfig }: ViewModeProp
const [ maxDepth ] = useNoteLabelInt(note, "maxNestingDepth") ?? -1;
const [ columnDefs, setColumnDefs ] = useState<ColumnDefinition[]>();
const [ rowData, setRowData ] = useState<TableData[]>();
+ const [ movableRows, setMovableRows ] = useState<boolean>();
const tabulatorRef = useRef<VanillaTabulator>(null);
const parentComponent = useContext(ParentComponent);
@@ -38,6 +39,7 @@ export default function TableView({ note, viewConfig, saveConfig }: ViewModeProp
});
setColumnDefs(columnDefs);
setRowData(rowData);
+ setMovableRows(movableRows);
});
}, [ note ]);
@@ -58,6 +60,10 @@ export default function TableView({ note, viewConfig, saveConfig }: ViewModeProp
footerElement={<TableFooter note={note} />}
events={contextMenuEvents}
persistence {...persistenceProps}
+ layout="fitDataFill"
+ index="branchId"
+ movableColumns
+ movableRows={movableRows}
/>
<TableFooter note={note} />
</>
diff --git a/apps/client/src/widgets/collections/table/tabulator.tsx b/apps/client/src/widgets/collections/table/tabulator.tsx
index 4ed890aa9e..2f8a005504 100644
--- a/apps/client/src/widgets/collections/table/tabulator.tsx
+++ b/apps/client/src/widgets/collections/table/tabulator.tsx
@@ -5,14 +5,13 @@ import "../../../../src/stylesheets/table.css";
import { ComponentChildren, RefObject } from "preact";
import { ParentComponent, renderReactWidget } from "../../react/react_utils";
-interface TableProps<T> extends Pick<Options, "persistence" | "persistenceReaderFunc" | "persistenceWriterFunc"> {
+interface TableProps<T> extends Omit<Options, "data" | "footerElement" | "index"> {
tabulatorRef: RefObject<VanillaTabulator>;
className?: string;
- columns: ColumnDefinition[];
data?: T[];
modules?: (new (table: VanillaTabulator) => Module)[];
- footerElement?: ComponentChildren;
events?: Partial<EventCallBackMethods>;
+ index: keyof T;
}
export default function Tabulator<T>({ className, columns, data, modules, tabulatorRef: externalTabulatorRef, footerElement, events, ...restProps }: TableProps<T>) {
@@ -34,7 +33,7 @@ export default function Tabulator<T>({ className, columns, data, modules, tabula
columns,
data,
footerElement: (parentComponent && footerElement ? renderReactWidget(parentComponent, footerElement)[0] : undefined),
- ...restProps
+ ...restProps,
});
tabulatorRef.current = tabulator;
@@ -59,7 +58,7 @@ export default function Tabulator<T>({ className, columns, data, modules, tabula
}, Object.values(events ?? {}));
// Change in data.
- useEffect(() => { tabulatorRef.current?.setData(data) }, [ data ]);
+ useEffect(() => { console.log("Got data ", data); tabulatorRef.current?.setData(data) }, [ data ]);
return (
<div ref={containerRef} className={className} />
diff --git a/apps/client/src/widgets/view_widgets/table_view/index.ts b/apps/client/src/widgets/view_widgets/table_view/index.ts
index 4383eada3a..c93700740a 100644
--- a/apps/client/src/widgets/view_widgets/table_view/index.ts
+++ b/apps/client/src/widgets/view_widgets/table_view/index.ts
@@ -61,14 +61,6 @@ export default class TableView extends ViewMode<StateInfo> {
const viewStorage = await this.viewStorage.restore();
this.persistentData = viewStorage?.tableData || {};
- let opts: Options = {
- layout: "fitDataFill",
- index: "branchId",
- movableColumns: true,
- movableRows,
- footerElement: buildFooter(this.parentNote),
- };
-
if (hasChildren) {
opts = {
...opts,