2

I have grid with the button in the generated column. See screenshot:

enter image description here

Depending on boolean value in the column "Has Stacktrace" I would like to show or hide the button "view" in the column "Stacktrace".

Should I extend Vaadin's com.vaadin.ui.renderers.ButtonRenderer or there is any simpler option?

4

1 回答 1

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;
                }
            });
于 2017-02-09T21:48:14.990 回答