termui icon indicating copy to clipboard operation
termui copied to clipboard

Guide on table with different sized columns

Open madpipeline opened this issue 4 years ago • 2 comments

Hello,

I've been trying to figure out how to use the table ColumnWidths to set my tables to have the proper widths in each column for it's content, but to no avail. An example code, or some documentation would be very useful for newcomers to the project on how to properly use this feature would be extremely useful.

madpipeline avatar Feb 24 '21 08:02 madpipeline

Not sure if you still need help, I was also trying to figure out how to size columns properly in a table. In looking at the source code, ColumnWidths is an array of integers specifying the width for each column. ColumnResizer seems to be a function that modifies the ColumnWidths directly during each call to Draw. Therefore usage is probably something like this:

table := NewTable()
table.ColumnResizer = func() {
    w := table.Inner.Dx()
    table.ColumnWidths = []int{w/2, w/2}
}

I think that if you do not need dynamic resizing, you can probably just set ColumnWidths directly.

Hope this helps.

dingyuchen avatar Jun 30 '21 02:06 dingyuchen

I know it seems obvious. I thought so too, but and example still would not hurt, in the documentation. This ticket will jut get buried at some point.

madpipeline avatar Jul 05 '21 05:07 madpipeline