-
trumbowyg table bugDEV/other things 2024. 9. 4. 15:15
How to fix a bug where the table width changes randomly.
trumbowyg.table.js
// Original code var setColWidths = function ($table, tableState, isUnitPercent = false) { var $colgroup = $('colgroup', $table); var $cols = $('col', $colgroup); var tableWidth = $table[0].offsetWidth; $table.css({ maxWidth: $table[0].offsetWidth, }); var columnCount = tableState[0].length; var colWidths = []; for (var columnIndex = 0; columnIndex < columnCount; columnIndex += 1) { var cellElement = findFirstCellAtIndex(tableState, columnIndex).element; var cellWidth = cellElement.getBoundingClientRect().width; if (isUnitPercent) { cellWidth = ((cellWidth / tableWidth) * 100) + '%'; } colWidths[columnIndex] = cellWidth; } for (var colIndex = 0; colIndex < columnCount; colIndex += 1) { $($cols[colIndex]).css({ width: colWidths[colIndex], }); } }; // fixed code var setColWidths = function ($table, tableState, isUnitPercent = false) { var $colgroup = $('colgroup', $table); var $cols = $('col', $colgroup); var tableWidth = $table[0].offsetWidth; $table.css({ maxWidth: $table[0].offsetWidth, }); var columnCount = tableState[0].length; var colWidths = []; for (var columnIndex = 0; columnIndex < columnCount; columnIndex += 1) { var cellElement = findFirstCellAtIndex(tableState, columnIndex).element; var cellWidth = cellElement.getBoundingClientRect().width; if (isUnitPercent) { cellWidth = ((cellWidth / tableWidth) * 100) + '%'; } colWidths[columnIndex] = Math.floor(cellWidth); } for (var colIndex = 0; colIndex < columnCount; colIndex += 1) { $($cols[colIndex]).css({ width: colWidths[colIndex], }); } };
'DEV > other things' 카테고리의 다른 글
yarn 설치하기 (1) 2024.10.07 trumbowyg color picker bug (0) 2024.09.04 Redis/MacOs Redis 설치 (0) 2024.08.29 Redis/MacOs Redis 설치 후 "Could not connect to Redis at 127.0.0.1:6379: Connection refused" 에러 (0) 2024.08.29 Certbot을 통해 무료 SSL 발급받기(임시 및 갱신) (0) 2024.08.19