This commit is contained in:
bakhirev 2024-08-12 09:17:17 +03:00
parent 1c2012bc94
commit 2e29d4ede2
5 changed files with 18 additions and 17 deletions

View file

@ -1,3 +0,0 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path stroke="#84858D" d="M15.41 16.59 10.83 12l4.58-4.59L14 6l-6 6 6 6 1.41-1.41z"></path>
</svg>

Before

Width:  |  Height:  |  Size: 198 B

View file

@ -1,3 +0,0 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path stroke="#84858D" d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path>
</svg>

Before

Width:  |  Height:  |  Size: 188 B

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -6,23 +6,30 @@ export default function getAdaptiveColumnWidth(
): number {
if (!offsetWidth) return 150;
// количество колонок и фиксированная ширина
const visibleColumns = columns.filter(({ isShow }: IColumn) => isShow);
const columnsWidth = visibleColumns.map((column: IColumn) => (
column.userWidth || column.defaultWidth || 0
));
const fixedWidth = columnsWidth.reduce((sum: number, width: number) => sum + width, 0);
const adaptiveColumnsCount = columnsWidth.filter((width: number) => !width).length;
let adaptiveColumnsCount = columnsWidth.filter((width: number) => !width).length;
if (!adaptiveColumnsCount) return 40;
const tableWidth = offsetWidth - fixedWidth;
// делаем предварительный расчёт
let adaptiveTableWidth = offsetWidth - fixedWidth;
let adaptiveColumnsWidth = Math.floor(adaptiveTableWidth / adaptiveColumnsCount);
// если адаптив < минималки, то адаптив делает перерасчет
let adaptiveTableWidth = tableWidth;
let adaptiveColumnsWidth = adaptiveTableWidth / adaptiveColumnsCount;
visibleColumns.forEach((column: IColumn) => {
if (!column.minWidth
|| column.minWidth < adaptiveColumnsWidth) return;
if (
(column.userWidth || column.defaultWidth) // если ширина известна
|| !column.minWidth // если минималки нет
|| column.minWidth < adaptiveColumnsWidth // если минималки меньше адаптива
|| !adaptiveColumnsCount // если столбиков уже нет
) return;
adaptiveTableWidth -= column.minWidth;
adaptiveColumnsCount -= 1;
adaptiveColumnsWidth = adaptiveTableWidth / adaptiveColumnsCount;
});