Project

General

Profile

How: WTableView size columns to content

Added by Russ Freeman over 11 years ago

How do I set the columns widths, of individual columns, to size to their contents?

...specifically I have a column that has buttons in it and I don't wish them to be hidden or have ellipsis on them but in different browsers I see different columns widths (Chrome is fine, IE9 and Firefox produce ellipsis).


Replies (11)

RE: How: WTableView size columns to content - Added by Russ Freeman over 11 years ago

Any suggestions?

I'm running into more and more cases where the WTableView columns don't meet the needs of my UI.

Right now I want a simple two column set up where the left column sizes to maximum and the right column contains a small amount of data (a number) but it should never have ellipsis and never wrap.

And the columns should fill the horizontal table space.

RE: How: WTableView size columns to content - Added by Koen Deforche over 11 years ago

Hey,

Currently this is only possible by making your WTableView setLayoutSizeAware(), and the react to size changes (in layoutSizeChanged()) to manually configure the width of the columns (take into account the 7 pixels extra padding per column).

Regards,

koen

RE: How: WTableView size columns to content - Added by Vincenzo Romano almost 10 years ago

What about column width in percentage?

I do know in advance the maximum column width in characters and I am using a non-proportional font.

So I can compute the optimal width for each column in percentage.

But when I try to setColumnWidth() accordingly, all columns get crippled as if they all had 1% width.

What am I missing?

RE: How: WTableView size columns to content - Added by Vincenzo Romano almost 10 years ago

Any idea why the following call loop doesn't work?

WTableView* tableview;
int totalWidthInChars;

/*columns[i]->size is the maximum content size for each column*/

totalWidthInChars = 0;
for( int i=0; i<columnNumber; i++ )
  totalWidthInChars += columns[i]->size;

for( int i=0; i<columnNumber; i++ )
  tableview->setColumnWidth( i, WLength( 100.0*columns[i]->size/totalWidthInChars, WLength::Percentage ) );

As stated in my previous post above, all columns are shown as if they all had the same tiny width.

RE: How: WTableView size columns to content - Added by Vincenzo Romano almost 10 years ago

By using the "Inspect element" by Mozilla Firefox v29 I have found an interesting point.

The "last" container for the table data is a <DIV>

<div  id="oessfvj" class="Wt-tv-contents"
style="position:absolute;width:224.0px;height:1720.0px;left:0.0px;right:auto;top:0.0px;bottom:auto;background-image:url("/resources/themes/default/stripes/stripe20px.gif");">
...
</div>

Within this container I have the columns.

As you can see I have a width of 224px to be divided among 12 columns.

While the "last" whole container that should contain the WTableView has a "width:1017ps" style definition (among all other ones),

Whith last whone container I nean the deapest element within the tree structure still recognizable.

The "last container" for the table data is the container that containds the data but not the header.

The "last container" for the table view is the container that contains the WTableView, there included the header and the scrollbar.

RE: How: WTableView size columns to content - Added by Koen Deforche almost 10 years ago

Hey,

You cannot set column widths as a percentage, but the documentation isn't clear about this. We'll fix that.

Regards,

koen

RE: How: WTableView size columns to content - Added by Vincenzo Romano almost 10 years ago

How can I set up an almost optimal column width, then? Any suggestion?

RE: How: WTableView size columns to content - Added by Koen Deforche almost 10 years ago

Hey,

You need to use the available width, which you can get from a layout-size-aware parent of the tableview.

See the discussion and solution here: http://redmine.emweb.be/boards/2/topics/2659 (which you actually participated in as well?).

Regards,

koen

RE: How: WTableView size columns to content - Added by Vincenzo Romano almost 10 years ago

As the program should run on a variety of screen sizes, a percentage-like solution would be preferrable over one with fixed widths in pixels.

I understood the previous suggestion but was hoping for a simpler solution...

RE: How: WTableView size columns to content - Added by Koen Deforche almost 10 years ago

Hey,

I agree that it would be nicer to have it simpler, but as a workaround it is usable?

Regards,

koen

RE: How: WTableView size columns to content - Added by Vincenzo Romano almost 10 years ago

I will try that and will let you know.

    (1-11/11)