mirror of
https://github.com/zadam/trilium.git
synced 2025-11-16 10:15:52 +01:00
feat(book/table): allow editing cell values
This commit is contained in:
@@ -1,11 +1,35 @@
|
||||
import { createGrid, AllCommunityModule, ModuleRegistry } from "ag-grid-community";
|
||||
import { buildData } from "./data.js";
|
||||
import { createGrid, AllCommunityModule, ModuleRegistry, columnDropStyleBordered, 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 { setLabel } from "../../../services/attributes.js";
|
||||
|
||||
ModuleRegistry.registerModules([ AllCommunityModule ]);
|
||||
|
||||
export default function renderTable(el: HTMLElement, parentNote: FNote, notes: FNote[]) {
|
||||
const info = getPromotedAttributeInformation(parentNote);
|
||||
|
||||
createGrid(el, {
|
||||
...buildData(parentNote, notes)
|
||||
...buildData(info, notes),
|
||||
...setupEditing(info)
|
||||
});
|
||||
}
|
||||
|
||||
function setupEditing(info: PromotedAttributeInformation[]): GridOptions<TableData> {
|
||||
return {
|
||||
onCellValueChanged(event) {
|
||||
if (event.type !== "cellValueChanged") {
|
||||
return;
|
||||
}
|
||||
|
||||
const noteId = event.data.noteId;
|
||||
const name = event.colDef.field;
|
||||
if (!name) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { newValue } = event;
|
||||
setLabel(noteId, name, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user