WTableView and force vertical scrollbar only
Added by Emeric Poupon over 10 years ago
Hello,
I used setOverflow(Wt::WContainerWidget::OverflowScroll) on my WTableWidget, and it shows both horizontal and vertical scrollbars.
Is there a way to only get the vertical scrollbar?
Maybe using css?
Best Regards,
Emeric
Replies (7)
RE: WTableView and force vertical scrollbar only - Added by Vincenzo Romano over 10 years ago
Yes, you need to resize the widget so it fits inside the container widget (or screen).
As there seems to be no WTableWidget
, I presume you are actually talking about a WTable
or a WTableView
.
In either case you can derive a class where you specialize the layoutSizeChanged
method.
Don't forget to make the table setLayoutSizeAware( true )
.
Of course you need to keep track of the actual content of the table and (somehow) be able to compute a relative column width.
I personally did it: it's not rocket science while not as easy as a snap.
RE: WTableView and force vertical scrollbar only - Added by Vincenzo Romano over 10 years ago
As an alternative (I personally dislike), you can use CSS to clip the widget.
Give the container widget an ID and/or a style class and then use CSS to horizontally clip just that.
RE: WTableView and force vertical scrollbar only - Added by Emeric Poupon over 10 years ago
Vincenzo Romano wrote:
Yes, you need to resize the widget so it fits inside the container widget (or screen).
As there seems to be noWTableWidget
, I presume you are actually talking about aWTable
or aWTableView
.
In either case you can derive a class where you specialize thelayoutSizeChanged
method.
Don't forget to make the tablesetLayoutSizeAware( true )
.
Of course you need to keep track of the actual content of the table and (somehow) be able to compute a relative column width.
I personally did it: it's not rocket science while not as easy as a snap.
Hello,
Thanks for you answer, but how do you accurately calculate the width of your columns when the scroll bar is shown?
The width of the scrollbar seems to depend on the browzser that is being used...
Regards,
Emeric
RE: WTableView and force vertical scrollbar only - Added by Vincenzo Romano over 10 years ago
I subtracted 7 pixel width from every single column that's disaplyed. As per documentation.
Everything else just worked.
RE: WTableView and force vertical scrollbar only - Added by Emeric Poupon over 10 years ago
I have two columns: "name" and "tracks"
Here is what I do (I want the second column to keep its width):
void
TableFilter::layoutSizeChanged (int width, int height)
{
std::size_t trackColumnSize = this->columnWidth(1).toPixels();
// Set the remaining size for the name column
this~~setColumnWidth(0, width~~ trackColumnSize - (7 * 2));
}
Without vertical scrollbar: I have to substract extra two pixels in order not to make the horizontal scrollbar be displayed
With the vertical scrollbar: the horizontal scroll bar is always shown since the formula does not seem to work.
This is another problem, but a good solution for me would be to make sure the vertical scrollbar is always displayed (even if not necessary)
Maybe I have to add something to the columnWidth method's result?
Regards,
RE: WTableView and force vertical scrollbar only - Added by Koen Deforche over 10 years ago
Hey Emeric,
You can do this using the following in CSS:
.Wt-itemview .tcontainer[onscroll] {
overflow-y: scroll !important;
}
Regards,
koen
RE: WTableView and force vertical scrollbar only - Added by Emeric Poupon over 10 years ago
This seems to be great, but how I can I resize the last column to fill the remaining room when the scroolbar is shown?
I guess I can't estimate the scrollbar's width since it is browser dependent?
Best Regards,
Emeric