How to create the Horizontal ScrollBar at the bottom of DataGrid as in GWT CellSampler example? - gwt

I like DataGrid since it has fixed header so wen user scrolldown they are still be able to see the column header.
However, if there are too many columns then the DataGrid will manage to fit all columns within the Fixed Width of the widget that contain it.
For example, if a 30 column DataGrid was put inside a center (with 100px) of a DockLayoutPanel then all 30 columns will be divided evenly within 100px, which is make it unreadable cos the with of each column is too small.
So, I would love to use DataGrid but the DataGrid should have a Horizontal ScrollBar at the bottom so if there are many column then the user can just scroll horizontally to the right to see the data.
If we do correctly, then it should be like the GWT CellSampler example http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellSampler
Clearly, the CellSampler used DataGid, but I didn't see any Horizontal ScrollBar code in there.
So how to make DataGrid to display as in the CellSampler example?

You should set the minimum width for your DataGrid:
myDataGrid.setMinimumTableWidth(600, Unit.PX);

I have done following for My Table Datagrid.
FlowPanel tablePanel = new FlowPanel();
tablePanel.add( table );
tablePanel.getElement().setAttribute( "style",
"overflow-x: auto;width: " + ( Window.getClientWidth() - 37 ) + "px;clear: both" );
add( tablePanel );

Related

ListGrid with auto size - missing columns

I'm using smartgwt ListGrid. The problem appears when it's empty, and if i manually set columns width, i can get some columns clipped in the view port and there is no horizontal scrolling so I can't access them.
But if I add an empty record, the scrollbar appears. I've fixed it by adding
setAutoFitData(Autofit.HORIZONTAL);
setAutoFitMaxColumns(3000);
setOverflow(Overflow.AUTO);
But I need to add some freezed columns to my listGrid. I'd like to use setFrozen(true) method, but its not compatible with setAutoFitData(Autofit.HORIZONTAL);
What I need is
to show a scrollbar if columns are out of the view port, even when list grid is empty.
some first columns must be frozen.
Everything works with the base List Grid with no additional options. But when i set
setShowEmptyMessage(false);
my scrollbar disappears.
Kind of workaround i've found:
setShowEmptyMessage(true);
setEmptyMessage(" ");

GXT ScrollBar overlapping content

I'm using setScrollMode(ScrollMode.AUTOY) to enable vertical scrolling when necessary on a VerticalLayoutContainer. However, the scrollbar overlaps the content of the container. The only way around this that I've seen is to call setAdjustForScroll(true). The problem with this is that The panel will then always reserve space for a scrollbar even when one is not present.
Is there a way to tell GXT to only adjust for a scrollbar when one is present? Or perhaps use an event handler (eg ResizeHandler) and check if the scrollbar is currently visible?
Instead of trying to check in a handler if the scrollbar is visible, isn't it just easier to not have the content in the VerticalLayoutContainer?
For example I have:
VerticalLayoutContainer vp = new VerticalLayoutContainer();
vp.setScrollMode(ScrollMode.AUTO);
vp.add(layer1, new VerticalLayoutData(1, -1));
vp.add(layer2, new VerticalLayoutData(1, -1));
vp.add(layer3, new VerticalLayoutData(1, -1));
the layers(1-3) contain the actual content and are different types Ex. VBoxLayoutContainer, Container, VerticalLayoutContainer.
It works for me. I don't think it is relevant but I am adding the vp to a CenterLayoutContainer that is added to the root panel.

automatic resize of the tab panel based on contents

Hello I have implemented something like
private VerticalPanel resultPanel;
private TabLayoutPanel tabPanel = new TabLayoutPanel(2.5, Unit.EM);
ResizeLayoutPanel resizePanel = new ResizeLayoutPanel();
myMethod(){
resizePanel.setWidth("100%");
resizePanel.setHeight("415px");
resizePanel.setWidget(tabPanel);
resultPanel = new VerticalPanel();
resultPanel.setWidth("100%");
resultPanel.add(resizePanel);
tabPanel.add(myVerticalPanel, tabHeader);
}
so the myVerticalPanel is the actual contents which is little large in height. As resizePanel height is set to 415px so rest of the contents are hidden.
I am looking for two things to achieve:
1. If there is a larger screen available then increase the tabPanel area to show more contents automatically
2. If screen is small then a scroll to appear to see rest of the contents
Please advise
You can try to replace the TabLayoutPanel with a HeaderPanel:
A panel that includes a header (top), footer (bottom), and content
(middle) area. The header and footer areas resize naturally. The
content area is allocated all of the remaining space between the
header and footer area.
Alternatively you can override the onResize() method your ResizeLayoutPanel calculate the height of your embedded content and set the appropriate height.
If you want scrolling functionality you have to embed your VerticalPanel in a ScrollPanel or use CSS to set the oferflow property.

How to have the container adjust to a GWT grid?

I have a DataGrid with a SimplePager and when theres less than the predefined number of rows per page (in this case 15) the container will show those rows and leave a white space in between the grid and the simplePager (where the other rows would be).
I have seen some mentions on other sites about rendering datagrid first and then fit it into the container, but i have no idea what this means (Or at least, i don't think they're saying its as easy as removing it from the parent and re-attaching it, since i've tried that already).
Thanks in advance.
My proposition - resize container after data fetch, after rendering of grid. It will be just something like this:
container.setHeight(grid.getOffsetHeight() + "px");

How to have one line per row in a cellTable?

I am using a CellTable on a ScrollPanel in GWT. My table has two columns and I want to give 10% and 90% of the width each. This is fine.
The problem is that I want to have one line of text per row in the table. That is if the content of one cell is too large to be showed in one line, I want to have either a horizontal scrolling bar or just truncate the text to fit it in one line.
Here is an extract of my code:
cellTable.addColumn(column1);
cellTable.addColumn(column2);
cellTable.setWidth("100%", true);
cellTable.setColumnWidth(column1, 10.0, Unit.PCT);
cellTable.setColumnWidth(column2, 90.0, Unit.PCT);
I also tried to use:
cellTable.setTableLayoutFixed(true);
but it doesn't change the layout.
Thanks a lot for your comments!
Use the CSS property "white-space: nowrap"
More info
You'll have to play with the word-wrap, overflow and possibly text-overflow CSS properties.