feat: Double click resize handle to resize to perfect width
This commit is contained in:
parent
3446488b08
commit
7b325a5ba0
@ -14,6 +14,7 @@ export default class ColumnManager {
|
|||||||
'fireEvent',
|
'fireEvent',
|
||||||
'header',
|
'header',
|
||||||
'datamanager',
|
'datamanager',
|
||||||
|
'cellmanager',
|
||||||
'style',
|
'style',
|
||||||
'wrapper',
|
'wrapper',
|
||||||
'rowmanager',
|
'rowmanager',
|
||||||
@ -59,6 +60,7 @@ export default class ColumnManager {
|
|||||||
bindEvents() {
|
bindEvents() {
|
||||||
this.bindDropdown();
|
this.bindDropdown();
|
||||||
this.bindResizeColumn();
|
this.bindResizeColumn();
|
||||||
|
this.bindPerfectColumnWidth();
|
||||||
this.bindFilter();
|
this.bindFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,6 +195,38 @@ export default class ColumnManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bindPerfectColumnWidth() {
|
||||||
|
$.on(this.header, 'dblclick', '.dt-cell .dt-cell__resize-handle', (e, $handle) => {
|
||||||
|
const $cell = $handle.parentNode.parentNode;
|
||||||
|
const { colIndex } = $.data($cell);
|
||||||
|
|
||||||
|
let longestCell = this.bodyRenderer.visibleRows
|
||||||
|
.map(d => d[colIndex])
|
||||||
|
.reduce((acc, curr) => acc.content.length > curr.content.length ? acc : curr);
|
||||||
|
|
||||||
|
let $longestCellHTML = this.cellmanager.getCellHTML(longestCell);
|
||||||
|
let $div = document.createElement('div');
|
||||||
|
$div.innerHTML = $longestCellHTML;
|
||||||
|
let cellText = $div.querySelector('.dt-cell__content').textContent;
|
||||||
|
|
||||||
|
let {
|
||||||
|
borderLeftWidth,
|
||||||
|
borderRightWidth,
|
||||||
|
paddingLeft,
|
||||||
|
paddingRight
|
||||||
|
} = $.getStyle(this.bodyScrollable.querySelector('.dt-cell__content'));
|
||||||
|
|
||||||
|
let padding = [borderLeftWidth, borderRightWidth, paddingLeft, paddingRight]
|
||||||
|
.map(parseFloat)
|
||||||
|
.reduce((sum, val) => sum + val);
|
||||||
|
|
||||||
|
let width = $.measureTextWidth(cellText) + padding;
|
||||||
|
this.datamanager.updateColumn(colIndex, { width });
|
||||||
|
this.setColumnHeaderWidth(colIndex);
|
||||||
|
this.setColumnWidth(colIndex);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
bindMoveColumn() {
|
bindMoveColumn() {
|
||||||
const $parent = $('.dt-row', this.header);
|
const $parent = $('.dt-row', this.header);
|
||||||
|
|
||||||
|
|||||||
@ -138,6 +138,10 @@ $.removeStyle = (elements, styleProps) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$.getStyle = (element, prop) => {
|
$.getStyle = (element, prop) => {
|
||||||
|
if (!prop) {
|
||||||
|
return getComputedStyle(element);
|
||||||
|
}
|
||||||
|
|
||||||
let val = getComputedStyle(element)[prop];
|
let val = getComputedStyle(element)[prop];
|
||||||
|
|
||||||
if (['width', 'height'].includes(prop)) {
|
if (['width', 'height'].includes(prop)) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user