Hi Guys,
I have the requerement to have a Grid in the detail Row of another Grid, and the inner Grid has to have hideable columns.
However, if I define any column as hideable in the inner Grid, it will not be visible in the inner Grid. Also the inner grid context menu (for showing/hiding columns) is always empty and almost not visible.
you can play areound with
innerGrid.getColumn(Locale_PROPERTY_language).setHidable(true);
innerGrid.getColumn(Locale_PROPERTY_country).setHidable(true);
innerGrid.getColumn(Locale_PROPERTY_NAME).setHidable(true);
by commenting the lines out, to see different strage behavior
See my Code Example:
package com.example.myapplication;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.annotations.Widgetset;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Component;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.DetailsGenerator;
import com.vaadin.ui.Grid.RowReference;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
@Theme("mytheme")
@Widgetset("com.example.myapplication.MyAppWidgetset")
public class MyUI extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();
Grid gridWithInnerGrid = getGridWithInnerGrid();
layout.addComponent(gridWithInnerGrid);
this.setContent(layout);
}
private Grid getGridWithInnerGrid() {
Grid grid = new Grid();
grid.setContainerDataSource(getLocaleContainer());
grid.setDetailsGenerator(new DetailsGenerator() {
@Override
public Component getDetails(RowReference rowReference) {
Grid innerGrid = new Grid();
innerGrid.setContainerDataSource(getLocaleContainer());
innerGrid.getColumn(Locale_PROPERTY_language).setHidable(true);
innerGrid.getColumn(Locale_PROPERTY_country).setHidable(true);
innerGrid.getColumn(Locale_PROPERTY_NAME).setHidable(true);
return innerGrid;
}
});
Object itemId = grid.getContainerDataSource().firstItemId();
grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId));
grid.getColumn(Locale_PROPERTY_language).setHidable(true);
grid.getColumn(Locale_PROPERTY_NAME).setHidable(true);
grid.getColumn(Locale_PROPERTY_NAME).setHidable(true);
grid.setSizeFull();
return grid;
}
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
public static final Object Locale_PROPERTY_language = "language";
public static final Object Locale_PROPERTY_country = "country";
public static final Object Locale_PROPERTY_NAME = "name";
private static final String Locales =
{ { "fi", "FI", "Finnish" }, { "de", "DE", "German" }, { "en", "US", "US - English" }, { "sv", "SE", "Swedish" } };
/**
* @return test container with Locale
*/
public static IndexedContainer getLocaleContainer() {
IndexedContainer localeContainer = new IndexedContainer();
localeContainer.addContainerProperty(Locale_PROPERTY_language, String.class, null);
localeContainer.addContainerProperty(Locale_PROPERTY_country, String.class, null);
localeContainer.addContainerProperty(Locale_PROPERTY_NAME, String.class, null);
for (int i = 0; i < Locales.length; i++) {
String id = Locales[i]
[2]
;
Item item = localeContainer.addItem(id);
item.getItemProperty(Locale_PROPERTY_language).setValue(Locales[i]
[0]
);
item.getItemProperty(Locale_PROPERTY_country).setValue(Locales[i]
[1]
);
item.getItemProperty(Locale_PROPERTY_NAME).setValue(Locales[i]
[2]
);
}
return localeContainer;
}
}
[/i]
[/i]
[/i]
[/i]