Datagrid insert button on each row

Hi guys,

How would I go about adding a button to each row of a datagrid that when clicked opens up the editor for the clicked item?

Nevermind, found it here: https://doc.cuba-platform.com/manual-6.5/gui_DataGrid.html

 @Inject
private DataGrid<MyEntity> myEntityDataGrid;

@Inject
private GroupDatasource<MyEntity, UUID> myEntityDs;

@Inject
private DataManager dataManager;

@Inject
private ComponentsFactory componentsFactory;

@Override
public void init(Map<String, Object> params) {


    DataGrid.Column column = myEntityDataGrid.addGeneratedColumn("scheduleButton",
            new DataGrid.ColumnGenerator<MyEntity, Component>() {
                int i = 1;
                @Override
                public Component getValue(DataGrid.ColumnGeneratorEvent<MyEntity> event) {
                    Button button = componentsFactory.createComponent(Button.class);
                    button.setCaption("Schedule");
                    button.setId("Button "+i);
                    i++;
                    button.setAction(new BaseAction("id") {
                        @Override
                        public void actionPerform(Component component) {
                            System.out.println("Button " + button.getId()+" Has Been Clicked");
                        }
                    });
                    return button;
                }

                @Override
                public Class<Component> getType() {
                    return Component.class;
                }
            });

    column.setRenderer(new WebComponentRenderer());


    super.init(params);
}
2 Likes