I use follwing code to generate dynamicly a grid and assign data out of an entity:
final Grid<KalTabelle> myGrid = new Grid<>(KalTabelle.class, false);
myGrid.addColumn(KalTabelle::getId).setKey("id").setHeader(CaptionUtils.resolveCaption(KalTabelle.class, "id"))
.setSortable(true);
String fieldName = null;
for(int i = 1; i <= this.days; i++)
{
final int val = i;
fieldName = "d" + String.valueOf(i);
try
{
final PropertyDescriptor objPropertyDescriptor = new PropertyDescriptor(fieldName, KalTabelle.class);
myGrid.addColumn(objPropertyDescriptor.getName())
.setHeader(fieldName)
.setSortable(true);
}
catch(final Exception e)
{
e.printStackTrace();
}
}
myGrid.setSizeFull();
myGrid.setSelectionMode(Grid.SelectionMode.SINGLE);
this.hlLayoutGrid.add(myGrid);
myGrid.setDataProvider(DataProvider.ofCollection(this.getAllKalTab()));
myGrid.getDataProvider().refreshAll();
I did this because my entity(KalTabelle.class) has 366 columns (like days of a year)
but instead
myGrid.addColumn(objPropertyDescriptor.getName())
.setHeader(fieldName)
.setSortable(true);
I would like to use a rendered column by
myGrid.addColumn(RenderedComponent.Renderer(TextfieldComponent::new))
.setHeader(fieldName)
.setKey(fieldName)
.setSortable(false);
but this did not work. The values are not assigned into the textfield.
My TextfieldComponent.class:
import com.rapidclipse.framework.server.data.renderer.RenderedComponent;
import com.rieder.pkkalender.dbmodel.KalTabelle;
import com.vaadin.flow.component.AttachEvent;
import com.vaadin.flow.component.ComponentEvent;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
public class TextfieldComponent extends VerticalLayout implements RenderedComponent<KalTabelle>
{
private KalTabelle selKalTab;
public TextfieldComponent()
{
super();
this.initUI();
}
@Override
public void renderComponent(final KalTabelle value)
{
this.selKalTab = value;
}
private void initUI()
{
this.textField = new TextField();
this.setSpacing(false);
this.setPadding(false);
this.textField.setSizeUndefined();
this.add(this.textField);
this.setSizeFull();
this.textField.addAttachListener(this::textField_onAttach);
} // </generated-code>
// <generated-code name="variables">
private TextField textField;
// </generated-code>
}
What did I wrong, or how can I use the redered component with a dynamic field assignment?
Any help is welcome
Thanks in advance