feat(book/table): store hidden columns

This commit is contained in:
Elian Doran
2025-06-25 16:18:34 +03:00
parent c7b16cd043
commit ccb9b7e5fb
7 changed files with 96 additions and 22 deletions

View File

@@ -1,25 +1,35 @@
import { createGrid, AllCommunityModule, ModuleRegistry, columnDropStyleBordered, GridOptions } from "ag-grid-community";
import { createGrid, AllCommunityModule, ModuleRegistry, GridOptions } from "ag-grid-community";
import { buildData, type TableData } from "./data.js";
import FNote from "../../../entities/fnote.js";
import getPromotedAttributeInformation, { PromotedAttributeInformation } from "./parser.js";
import getPromotedAttributeInformation from "./parser.js";
import { setLabel } from "../../../services/attributes.js";
import applyHeaderCustomization from "./header-customization.js";
import ViewModeStorage from "../view_mode_storage.js";
import { type StateInfo } from "./storage.js";
ModuleRegistry.registerModules([ AllCommunityModule ]);
export default function renderTable(el: HTMLElement, parentNote: FNote, notes: FNote[]) {
export default async function renderTable(el: HTMLElement, parentNote: FNote, notes: FNote[], storage: ViewModeStorage<StateInfo>) {
const info = getPromotedAttributeInformation(parentNote);
const viewStorage = await storage.restore();
const initialState = viewStorage?.gridState;
createGrid(el, {
...buildData(info, notes),
...setupEditing(info),
onGridReady(event) {
...setupEditing(),
initialState,
async onGridReady(event) {
applyHeaderCustomization(el, event.api);
},
onStateUpdated(event) {
storage.store({
gridState: event.api.getState()
});
}
});
}
function setupEditing(info: PromotedAttributeInformation[]): GridOptions<TableData> {
function setupEditing(): GridOptions<TableData> {
return {
onCellValueChanged(event) {
if (event.type !== "cellValueChanged") {
@@ -37,3 +47,4 @@ function setupEditing(info: PromotedAttributeInformation[]): GridOptions<TableDa
}
}
}