Question

I tried to use DataGrid and put it in the stacklayoutpanel.At the time when I provide the data for the ListDataProvider, the CellTable is not visible in the browser because it's on a non active tab (although it's visible in the DOM tree). After switching to the tab containing the CellTable there is no data in it. If the tab is active at time of data provisioning the table is filled correctly. Since I have made a column sortable, if I clicked the sorting, the data would be displayed correctly. I want the data to be displayed automatically when I click the other inative tab. This will not be the problem if I switch to use celltable.

I knew this was the bug in GWT and it is fixed in GWT 2.5 RC. But my boss does not want me to use GWT2.5RC yet. I have to workaround to fix this. I knew that someone said datagrid.redraw() could sort of fix it. I tired it, but the display is weird. For example, I have 10 rows in DataGrid, after selecting the 2nd tab, redraw() is called, the data is automatically displayed, but there is only like 10px of block displaying the data and the scroll bar. I have to scroll down to see other rows. There are lots of space in the bottom of the tab not being used. Could anyone tell me how to fix this? So did I use the wrong way to fix it? is there anything else I can do to fix this problem. Could anyone give me some tips please.

Thanks

Best Regards

Was it helpful?

Solution

I have been struggled with this thing for almost 3 days. Thanks for Papick G. Taboada and Thomas Broyer. You guys' ideas are really helpful. Bascially either of your solution does not solve the problem. but after I combined both solutions, dang~ it worked!!.

So. the completed solution is that, add the selection handler on the non-active tab, then when the event is called, used datagrid.onResize() and then stackLayoutPanel.forcelayout(). This can solve my problem. I have also tried replacing datagrid.onResize() with datagrid.redraw(). It works as well.

I hope this can help other people who have the same problem before using GWT 2.5RC

OTHER TIPS

I came across this problem with a DataGrid within and Panel that was in a StackPanelLayout. DataGrid implements RequiresResize, so I made the Panel that contained the DataGrid implement RequiresResize so it could call onResize() for the DataGrid.

in the Panel that contained the DataGrid

@Override
public void onResize()
{
    dataGrid.onResize();
}

On the StackLayoutPanel

    stackLayoutPanel.addSelectionHandler(new SelectionHandler<Integer>() {

        // http://code.google.com/p/google-web-toolkit/issues/detail?id=6889
        @Override
        public void onSelection(SelectionEvent<Integer> event) {
            Integer selectedItem = event.getSelectedItem();
            StackLayoutPanel panel = (StackLayoutPanel) event.getSource();
            Widget  selectedWidget = panel.getWidget(selectedItem);
            if (selectedWidget != null && selectedWidget instanceof RequiresResize)
            {
                ((RequiresResize)selectedWidget).onResize();
            }
        }
    });

I believe a more general answer would be that any container in a StackLayoutPanel that contains a widget that implements RequiresResize should also implement RequiresResize and pass it on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top