cli-table2 icon indicating copy to clipboard operation
cli-table2 copied to clipboard

Shrinking a row after a call to `table.toString()` results in a table with no outer right border

Open mgroenhoff opened this issue 7 years ago • 0 comments

When calling table.toString(), either directly or indirectly (via table.width), tableLayout.computeWidths() and tableLayout.computeHeights() modifies this.options.colWidths and this.options.rowHeights respectively which causes the values to be reused or left behind in some way (i haven't tracked down the exact cause).

The use case: I have some code that creates a row with some cells and after a while it checks the width of the resulting table (via table.width thus calling table.toString() etc.). If it then exceeds a certain amount if pops the last cell of the row and adds it to a new row and adding that row to the table.

The problem: Because table.options.colWidths now contains an element for the cell i moved from the end of the first row to the beginning of the second row. The table.toString() somehow results in a table with no outer right border.

My temporary solution:

// Force recalculation of column widths
table.options.colWidths = [];
table.options.rowHeights = []; // Probably unnecessary but just to be sure
return table.toString();

mgroenhoff avatar May 19 '17 13:05 mgroenhoff