如何隐藏网格中生成列中的按钮?

时间:2017-02-02 21:05:56

标签: vaadin7 vaadin-grid

我在生成的列中有按钮的网格。见截图:

enter image description here

取决于列中的布尔值"具有Stacktrace"我想显示或隐藏按钮" view"在列#34; Stacktrace"。

我应该延伸Vaadin的com.vaadin.ui.renderers.ButtonRenderer还是有更简单的选项?

1 个答案:

答案 0 :(得分:0)

我做了以下解决方法,但我仍然想知道如何制作按钮:

// create container
IndexedContainer container = new IndexedContainer(...);
container.addContainerProperty("stacktrace", String.class, null);

// set data
importSession.getRows().forEach(importSessionRow -> {
    Item item = gpcontainer.getItem(importSessionRow.getId());
    item.getItemProperty("stacktrace").setValue(importSessionRow.isHasStacktrace() ? "/admin/instrument/import/row/" + importSessionRow.getId() + "/stacktrace.html" : null);
});

// set renderer
grid.getColumn("stacktrace").setRenderer(new HtmlRenderer(),
            new Converter<String, String>() {
                @Override
                public String convertToModel(String value,
                                             Class<? extends String> targetType, Locale locale)
                        throws Converter.ConversionException {
                    return "not implemented";
                }

                @Override
                public String convertToPresentation(String value,
                                                    Class<? extends String> targetType, Locale locale)
                        throws Converter.ConversionException {
                    return value != null ? "<a href='" + value + "' target='_blank'>view</a>" : null;
                }

                @Override
                public Class<String> getModelType() {
                    return String.class;
                }

                @Override
                public Class<String> getPresentationType() {
                    return String.class;
                }
            });