Skip to content

Commit da32722

Browse files
Add minimum resizable column width based on header content (#1444)
1 parent 9e22a8e commit da32722

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

webapp/src/components/DynamicDataTable.vue

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@
7474
</template>
7575
<template #empty> No entries found. </template>
7676

77-
<Column v-if="showButtons" class="checkbox" selection-mode="multiple"></Column>
77+
<Column
78+
v-if="showButtons"
79+
class="checkbox"
80+
selection-mode="multiple"
81+
:style="{ minWidth: '3.5ch' }"
82+
></Column>
7883

7984
<!-- <Column expander style="width: 5rem" /> -->
8085
<Column
@@ -83,6 +88,7 @@
8388
:field="column.field"
8489
sortable
8590
:class="{ 'filter-active': isFilterActive(column.field) }"
91+
:style="{ minWidth: getColumnMinWidth(column) }"
8692
:filter-menu-class="column.field === 'type' || column.field === 'date' ? 'no-operator' : ''"
8793
>
8894
<template #header>
@@ -431,6 +437,7 @@ export default {
431437
],
432438
};
433439
},
440+
434441
computed: {
435442
rows() {
436443
return this.$store.state.datatablePaginationSettings[this.dataType].rows;
@@ -619,6 +626,32 @@ export default {
619626
});
620627
},
621628
methods: {
629+
getColumnMinWidth(column) {
630+
const COLUMN_BASE_PADDING = 2.5;
631+
const CHAR_WIDTH_ESTIMATE = 0.75;
632+
const SORT_ICON_SPACE = 2.5;
633+
const FILTER_BUTTON_WIDTH = 3.5;
634+
const HEADER_ICON_SPACE = 2.5;
635+
const MIN_COLUMN_WIDTH = 10;
636+
637+
let minWidth = COLUMN_BASE_PADDING;
638+
639+
if (column.header) {
640+
minWidth += column.header.length * CHAR_WIDTH_ESTIMATE;
641+
}
642+
643+
if (column.icon) {
644+
minWidth += HEADER_ICON_SPACE;
645+
}
646+
647+
minWidth += SORT_ICON_SPACE;
648+
649+
if (column.filter) {
650+
minWidth += FILTER_BUTTON_WIDTH;
651+
}
652+
653+
return Math.max(minWidth, MIN_COLUMN_WIDTH) + "ch";
654+
},
622655
onSort(event) {
623656
const sortedColumns = event.multiSortMeta || [];
624657

0 commit comments

Comments
 (0)