mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 23:29:02 +02:00
feat(views/table): hide draggable rows if not supported
This commit is contained in:
parent
ccd935b562
commit
8d29c5fe1b
@ -1,7 +1,7 @@
|
|||||||
import { RelationEditor } from "./relation_editor.js";
|
import { RelationEditor } from "./relation_editor.js";
|
||||||
import { NoteFormatter, NoteTitleFormatter, RowNumberFormatter } from "./formatters.js";
|
import { NoteFormatter, NoteTitleFormatter, RowNumberFormatter } from "./formatters.js";
|
||||||
import { applyHeaderMenu } from "./header-menu.js";
|
import { applyHeaderMenu } from "./header-menu.js";
|
||||||
import type { ColumnDefinition } from "tabulator-tables";
|
import type { ColumnDefinition, Tabulator } from "tabulator-tables";
|
||||||
import { LabelType } from "../../../services/promoted_attribute_definition_parser.js";
|
import { LabelType } from "../../../services/promoted_attribute_definition_parser.js";
|
||||||
|
|
||||||
type ColumnType = LabelType | "relation";
|
type ColumnType = LabelType | "relation";
|
||||||
@ -42,7 +42,7 @@ const labelTypeMappings: Record<ColumnType, Partial<ColumnDefinition>> = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export function buildColumnDefinitions(info: AttributeDefinitionInformation[], existingColumnData?: ColumnDefinition[]) {
|
export function buildColumnDefinitions(info: AttributeDefinitionInformation[], movableRows: boolean, existingColumnData?: ColumnDefinition[]) {
|
||||||
const columnDefs: ColumnDefinition[] = [
|
const columnDefs: ColumnDefinition[] = [
|
||||||
{
|
{
|
||||||
title: "#",
|
title: "#",
|
||||||
@ -50,7 +50,7 @@ export function buildColumnDefinitions(info: AttributeDefinitionInformation[], e
|
|||||||
hozAlign: "center",
|
hozAlign: "center",
|
||||||
resizable: false,
|
resizable: false,
|
||||||
frozen: true,
|
frozen: true,
|
||||||
rowHandle: true,
|
rowHandle: movableRows,
|
||||||
formatter: RowNumberFormatter
|
formatter: RowNumberFormatter
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,12 @@ export function NoteTitleFormatter(cell: CellComponent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function RowNumberFormatter(cell: CellComponent) {
|
export function RowNumberFormatter(cell: CellComponent) {
|
||||||
return `<span class="bx bx-dots-vertical-rounded"></span> ` + cell.getRow().getPosition(true);
|
let html = "";
|
||||||
|
if (cell.getColumn().getDefinition().rowHandle) {
|
||||||
|
html += `<span class="bx bx-dots-vertical-rounded"></span> `;
|
||||||
|
}
|
||||||
|
html += cell.getRow().getPosition(true);
|
||||||
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildNoteLink(noteId: string) {
|
function buildNoteLink(noteId: string) {
|
||||||
|
@ -124,9 +124,9 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
const viewStorage = await this.viewStorage.restore();
|
const viewStorage = await this.viewStorage.restore();
|
||||||
this.persistentData = viewStorage?.tableData || {};
|
this.persistentData = viewStorage?.tableData || {};
|
||||||
|
|
||||||
const columnDefs = buildColumnDefinitions(info);
|
|
||||||
const { definitions: rowData, hasChildren } = await buildRowDefinitions(this.parentNote, info);
|
const { definitions: rowData, hasChildren } = await buildRowDefinitions(this.parentNote, info);
|
||||||
const movableRows = canReorderRows(this.parentNote) && !hasChildren;
|
const movableRows = canReorderRows(this.parentNote) && !hasChildren;
|
||||||
|
const columnDefs = buildColumnDefinitions(info, movableRows);
|
||||||
|
|
||||||
this.api = new Tabulator(el, {
|
this.api = new Tabulator(el, {
|
||||||
layout: "fitDataFill",
|
layout: "fitDataFill",
|
||||||
@ -249,7 +249,7 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const info = getAttributeDefinitionInformation(this.parentNote);
|
const info = getAttributeDefinitionInformation(this.parentNote);
|
||||||
const columnDefs = buildColumnDefinitions(info, this.persistentData?.columns);
|
const columnDefs = buildColumnDefinitions(info, !!this.api.options.movableRows, this.persistentData?.columns);
|
||||||
this.api.setColumns(columnDefs);
|
this.api.setColumns(columnDefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user