Reset settings facet

I need to provide a mechanism to reset the settings facet on list views. That is, to reset the selected columns, column order, column widths, etc. to the defaults defined in the view.

I’ve created a button on the view that deletes the view key from UserSettingsCache. However, the user must switch to another view and come back before they see the default settings of the view.

Is there a way to reset the settings and see the change immediately without switching views? Below is my button code. Perhaps there is a better solution:

    @Autowired
    private UserSettingsCache userSettingsCache;

    @Subscribe(id = "clearSettings", subject = "clickListener")
    protected void onClearSettingsClick(final ClickEvent<JmixButton> event) {
        var viewId = UiComponentUtils.getCurrentView().getId();
        if(viewId.isPresent()) {
            userSettingsCache.delete(viewId.get());
        }
    }

Thanks!

Hello!

Yes, components are loaded from XML only when the view is opened. Therefore, reopening the view or refreshing the page will update the UI.

The component XML element is stored in the component loader, and it is not directly accessible from the opened view. I think the only solution is to override the DataGrid component and its loader, storing the XML element object within the component. This would allow you to read the element and reset the column properties.

Keep in mind that to completely remove user settings, you should also delete them from the database. You can use UserSettingsService#delete().

Thanks! For now, I’ve simply created a view to the UserSettings entity where the user can delete any of their own view settings from the database and I clear the cached viewId at the same time. That way when they navigate back to the view, they see the default layout.

1 Like