Hi,
I am trying to resize all column widths programatically in order to obtain the same result than if a user would do the following actions:
- Select all cells (Ctrl+A)
- Hover a column header until the resize-handle appears
- Double-click on it
But I cannot find the correct method to call. Would you have an idea ?
What I have right now does not work unless I first hover the handle manually. So it is useless to me in this form:
let domID = 'element_HTcontainer_' + element.id; let handleJquery = $('#' + domID + ' .manualColumnResizer'); let maxSecurity = 0; while (handleJquery.length <= 0 && maxSecurity < 100) { handleJquery = $('#' + domID + ' .manualColumnResizer'); maxSecurity++; } if (handleJquery && handleJquery.length > 0) { const handleDom = handleJquery[0]; let sheet = document.styleSheets[0]; if (sheet) { // Adds CSS rules to hide highlight on headers, cells and borders let indexHeaders = sheet.insertRule('#' + domID + ` tbody th.ht__active_highlight, .handsontable thead th.ht__active_highlight {background: #f0f0f0 !important; opacity: 1;}`); let indexCells = sheet.insertRule('#' + domID + ` td.area::before {background-color: #fff !important;}`); let indexBorders = sheet.insertRule('#' + domID + ` .wtBorder {display: none !important;}`); // Resetting handle handleDom.dispatchEvent( new MouseEvent('mouseup', { bubbles: true, cancelable: true, view: window, }) ); // 1. Selects all cells $scope.hots[element.id]?.selectAll(); setTimeout(() => { // 2. Simulates double-click for (let i = 0; i < 2; i++) { handleDom.dispatchEvent( new MouseEvent('mousedown', { bubbles: true, cancelable: true, view: window, }) ); setTimeout(() => { handleDom.dispatchEvent( new MouseEvent('mouseup', { bubbles: true, cancelable: true, view: window, }) ); }, 50); } setTimeout(() => { // 3. Deselects all cells $scope.hots[element.id]?.deselectCell(); // Removes previously introduced CSS rules sheet?.deleteRule(indexCells); sheet?.deleteRule(indexHeaders); sheet?.deleteRule(indexBorders); }, 500); }, 150); } }