Dynamically enable wordwrap/word unwrap for a cell

Tags: #<Tag:0x00007efc645840f0> #<Tag:0x00007efc65207ed0>

This may be interest to others. I have single column that by default I want word wrapping turned off. Then when a cell is selected I want word wrapping enabled, when I exit the cell I want word wrapping turned off for that cell.
Handsontable version 14.3.0 Javascript.
(editor_sheet is the Handsontable reference)

The following worked for me.
When loading the table. Set each cell in the column to:
editor_sheet.setCellMeta(index, output_idx, ‘className’, ‘htNoWrap’);
I then added two hook handlers.
editor_sheet.addHook(‘afterOnCellMouseDown’, function(ev) {
var selected = editor_sheet.getSelected();
if (selected != null) {
var item = selected[0];
header_row = editor_sheet.getDataAtRow(0);
output_idx = header_row.indexOf(‘output’);
if (item[1] == output_idx) && (item[3] == output_idx) {
var row = Math.min(item[0], item[2]);
editor_sheet.setCellMeta(row, output_idx, ‘className’, ‘htWrap’);
editor_sheet.render();
};
};
});

editor_sheet.addHook(‘afterOnCellMouseOut’, function(ev) {
var selected = editor_sheet.getSelected();
if (selected != null) {
var item = selected[0];
header_row = editor_sheet.getDataAtRow(0);
output_idx = header_row.indexOf(‘output’);
if (item[1] == output_idx) && (item[3] == output_idx) {
var row = Math.min(item[0], item[2]);
editor_sheet.setCellMeta(row, output_idx, ‘className’, ‘htNoWrap’);
editor_sheet.render();
};
};
});

Hi @eric

Thank you for joining our community and sharing your solution. We really appreciate your input.

I will close the issue, as there are no further questions. But fear not—Google already indexed the thread, so if someone has the same issue, it will be available here to read.