This is what I want. If my table width does not fit into the specified allowed values (in this case, the table should take up no more than 55% of the width of the container in which it is located together with the graph), then a horizontal scroll appears and a vertical one (if necessary).
But if my table in actual width (in terms of content) is less than the maximum values (less than 55% of the width of the parent container), then it should not stretch, leaving empty space and drawing the vertical scroll away from the table and eating up some of the space near the graph. The vertical scroll should be located next to the table, and the graph should take up all the space available to it.
@adrian.szymanski @aleksandra_budnik Could you suggest ways to solve this problem? It seems trivial.
upd. I made such an implementation. I gave up the idea of setting the width for the table itself in the afterInit hook, now I set the width for the container in which the table is. This way, side effects associated with the disappearing scroll and resetting the scroll when editing disappear.
It looks hacky, since there is a direct call to the DOM
/**
* Sets the width of the table container according to its actual width on the page.
*
* The function takes an instance of Handsontable and adjusts the width of the container
* with id="spreadsheetContainer" so that it matches the width of the inner `.wtHider` container
* with a small additional margin. This margin (`SCROLLBAR_MARGIN`) is necessary to ensure that
* the vertical scrollbar does not stick too close to the table, leaving a small visual gap,
* and also to prevent the appearance of a horizontal scrollbar.
*
* @param hot - the Handsontable instance for which the width needs to be updated.
*/
const updateTableWidthContainer = (hot: Handsontable) => {
if (!hot) return;
const SCROLLBAR_MARGIN = 12;
const wtHider = hot.rootElement.querySelector('.wtHider');
const spreadsheetContainer = document.getElementById('spreadsheetContainer');
if (spreadsheetContainer && wtHider) {
spreadsheetContainer.style.width = `${wtHider.clientWidth + SCROLLBAR_MARGIN}px`;
}
};
const baseTableSettings: Partial<GridSettings> = {
data,
columns,
rowHeaders,
cell,
afterChange: updateCharacteristicsSpreadsheetData,
beforePaste,
beforeAutofill,
height: 690,
rowHeaderWidth: 45,
maxRows: data.length,
afterInit: function (this: Handsontable) {
updateTableWidthContainer(this)
},
}
<div className={cls.mainSection}>
<div className={cls.spreadsheetContainer} id='spreadsheetContainer'>
<TailraceCharacteristicsSpreadsheet />
</div>
<div className={cls.chartContainer}>
<TailraceCharacteristicsChart />
</div>
</div>