Removing an existing icon form a TreeDataGrid column with an iconRenderer

Hi,

I have a TreeDataGrid representing products and their categories. The dataGrid has a column with an iconRenderer, and I want to have a “folder” icon near every category. So I set the icon in the columnGenerator like this:

event.getItem().isDirectory() ? JmixIcon.FOLDER : null;

Now, if I change the order of rows in the table (expand or sort), the rows having the icon never get rid of it. However, if I don’t use null but put some other icon, everything works fine:

event.getItem().isDirectory() ? JmixIcon.FOLDER : JmixIcon.OK;

So the question is: what should iconRenederer’s columnGenerator return to remove an existing icon?

Hello Vadim!

Looks like a bug in DataGrid component. Thank you for reporting the problem! I’ve created an issue: DataGrid IconRenderer does not reset icon if return value is null · Issue #1550 · jmix-framework/jmix · GitHub

You can workaround the problem by providing ComponentRenderer instead of IconRenderer:

@Autowired
private UiComponents uiComponents;

@Install(to = "filesTable.icon", subject = "columnGenerator")
private Component filesTableIconColumnGenerator(DataGrid.ColumnGeneratorEvent<File> event) {
    Label label = uiComponents.create(Label.class);
    if (Boolean.TRUE.equals(event.getItem().getIsDirectory())) {
        label.setIconFromSet(JmixIcon.FOLDER);
    }
    return label;
}
1 Like

Hello Roman,

Thanks!