mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 20:19:05 +01:00
feat(views/table): allow hiding number row & title
This commit is contained in:
parent
8b0fdaccf4
commit
a25ce42490
@ -108,4 +108,15 @@ describe("restoreExistingData", () => {
|
||||
const restored = restoreExistingData(newDefs, oldDefs);
|
||||
expect(restored).toStrictEqual(newDefs);
|
||||
});
|
||||
|
||||
it("allows hiding the row number column", () => {
|
||||
const newDefs: ColumnDefinition[] = [
|
||||
{ title: "#", headerSort: false, hozAlign: "center", resizable: false, frozen: true, rowHandle: false },
|
||||
]
|
||||
const oldDefs: ColumnDefinition[] = [
|
||||
{ title: "#", headerSort: false, hozAlign: "center", resizable: false, rowHandle: false, visible: false },
|
||||
];
|
||||
const restored = restoreExistingData(newDefs, oldDefs);
|
||||
expect(restored[0].visible).toStrictEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
@ -41,7 +41,7 @@ const labelTypeMappings: Record<ColumnType, Partial<ColumnDefinition>> = {
|
||||
}
|
||||
};
|
||||
|
||||
export function buildColumnDefinitions(info: AttributeDefinitionInformation[], movableRows: boolean, existingColumnData?: ColumnDefinition[], position?: number) {
|
||||
export function buildColumnDefinitions(info: AttributeDefinitionInformation[], movableRows: boolean, existingColumnData: ColumnDefinition[] | undefined, position?: number) {
|
||||
let columnDefs: ColumnDefinition[] = [
|
||||
{
|
||||
title: "#",
|
||||
@ -102,10 +102,10 @@ export function restoreExistingData(newDefs: ColumnDefinition[], oldDefs: Column
|
||||
.filter(item => (item.field && newItemsByField.has(item.field!)) || item.title === "#")
|
||||
.map(oldItem => {
|
||||
const data = newItemsByField.get(oldItem.field!)!;
|
||||
if (oldItem.width) {
|
||||
if (oldItem.width !== undefined) {
|
||||
data.width = oldItem.width;
|
||||
}
|
||||
if (oldItem.visible) {
|
||||
if (oldItem.visible !== undefined) {
|
||||
data.visible = oldItem.visible;
|
||||
}
|
||||
return data;
|
||||
|
||||
@ -69,7 +69,6 @@ function showColumnContextMenu(_e: UIEvent, column: ColumnComponent, parentNote:
|
||||
},
|
||||
{
|
||||
title: t("table_view.hide-column", { title }),
|
||||
enabled: !!field,
|
||||
uiIcon: "bx bx-hide",
|
||||
handler: () => column.hide()
|
||||
},
|
||||
@ -129,7 +128,6 @@ function showColumnContextMenu(_e: UIEvent, column: ColumnComponent, parentNote:
|
||||
title,
|
||||
checked: column.isVisible(),
|
||||
uiIcon: "bx bx-empty",
|
||||
enabled: !!field,
|
||||
handler: () => column.toggle()
|
||||
});
|
||||
}
|
||||
|
||||
@ -137,7 +137,7 @@ export default class TableView extends ViewMode<StateInfo> {
|
||||
|
||||
const { definitions: rowData, hasSubtree: hasChildren } = await buildRowDefinitions(this.parentNote, info);
|
||||
const movableRows = canReorderRows(this.parentNote) && !hasChildren;
|
||||
const columnDefs = buildColumnDefinitions(info, movableRows);
|
||||
const columnDefs = buildColumnDefinitions(info, movableRows, this.persistentData.columns);
|
||||
let opts: Options = {
|
||||
layout: "fitDataFill",
|
||||
index: "branchId",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user