feat(views/table): disable drag if sorted

This commit is contained in:
Elian Doran 2025-06-27 20:30:36 +03:00
parent 6a0b24f032
commit bb0f384a39
No known key found for this signature in database
2 changed files with 53 additions and 48 deletions

View File

@ -37,8 +37,7 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) {
}, },
{ {
field: "title", field: "title",
editable: true, editable: true
rowDrag: true,
}, },
{ {
field: "position" field: "position"

View File

@ -81,8 +81,8 @@ export default class TableView extends ViewMode<StateInfo> {
this.api = createGrid(el, { this.api = createGrid(el, {
...buildData(parentNote, info, notes), ...buildData(parentNote, info, notes),
...setupEditing(), ...this.setupEditing(),
...setupDragging(), ...this.setupDragging(),
initialState, initialState,
async onGridReady(event) { async onGridReady(event) {
applyHeaderCustomization(el, event.api); applyHeaderCustomization(el, event.api);
@ -101,9 +101,7 @@ export default class TableView extends ViewMode<StateInfo> {
}); });
} }
} private setupEditing(): GridOptions<TableData> {
function setupEditing(): GridOptions<TableData> {
return { return {
onCellValueChanged(event) { onCellValueChanged(event) {
if (event.type !== "cellValueChanged") { if (event.type !== "cellValueChanged") {
@ -130,8 +128,13 @@ function setupEditing(): GridOptions<TableData> {
} }
} }
function setupDragging() { private setupDragging() {
return { if (this.parentNote.hasLabel("sorted")) {
return {};
}
const config: GridOptions<TableData> = {
rowDragEntireRow: true,
onRowDragEnd(e) { onRowDragEnd(e) {
const fromIndex = e.node.rowIndex; const fromIndex = e.node.rowIndex;
const toIndex = e.overNode?.rowIndex; const toIndex = e.overNode?.rowIndex;
@ -153,4 +156,7 @@ function setupDragging() {
} }
} }
}; };
return config;
} }
}