Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declarative renderers for DataGrid columns #1177

Closed
Flaurite opened this issue Nov 7, 2022 · 0 comments
Closed

Declarative renderers for DataGrid columns #1177

Flaurite opened this issue Nov 7, 2022 · 0 comments
Assignees
Milestone

Comments

@Flaurite
Copy link
Contributor

Flaurite commented Nov 7, 2022

Description

For now, we cannot change formatting of column values in DataGrid like in classic UI:

<column id="measureDate">
     <formatter>
            <date format="dd/MM/yyyy HH:mm:ss"/>
      </formatter>
</column>

Solution

The following renderers can be defined declaratively in XML:

  • localDateRenderer
  • localDateTimeRenderer
  • numberRenderer

For example:

<column property="dueDate">
    <localDateRenderer format="yyyy-MM-dd"/>
</column>

Alternatively, renderers can by supplied in a view controller using the new @Supply annotation. Method annotated with @Supply returns a value that will be passed as a input parameter to a method defined by subject.

In the example below, the returned ComponentRenderer instance is used as an input parameter for Column#setRenderer(Renderer):

@Supply(to = "tasksDataGrid.status", subject = "renderer")
private Renderer<Task> tasksDataGridStatusRenderer() {
    return new ComponentRenderer<>(Span::new, (span, task) -> {
        if (task.getStatus() == null) {
            span.getElement().removeAttribute("theme");
            span.getElement().removeAllChildren();
        } else {
            String theme = switch (task.getStatus()) {
                case OPEN -> "success";
                case CLOSED -> "error";
            };

            span.getElement().setAttribute("theme", "badge " + theme);
            span.setText(task.getName());
        }
    });
}

From now, columns can be defined without property attribute. In this case, EmptyValueProvider is set for a column and can be replaced by a Renderer later on, e.g.:

<column key="test" header="TEST"/>
@Supply(to = "tasksDataGrid.test", subject = "renderer")
private Renderer<Task> tasksDataGridTestRenderer() {
    return new TextRenderer<>(item ->
            "Test: " + item.getName());
}

Result (for all code above):
Screenshot 2023-07-28 at 14 59 16

For QA:

Probably wait for https://youtrack.jmix.io/issue/JST-4176/Support-new-Supply-annotation

@glebfox glebfox self-assigned this May 16, 2023
@glebfox glebfox added size: M candidate Possible candidate for future releases labels Jul 5, 2023
@knstvk knstvk added this to October 2023 release 2.1 in Jmix Roadmap Jul 12, 2023
@knstvk knstvk changed the title [DataGrid] Provide formatter for columns Formatter for DataGrid columns Jul 12, 2023
@glebfox glebfox removed the candidate Possible candidate for future releases label Jul 24, 2023
@glebfox glebfox removed this from October 2023 release 2.1 in Jmix Roadmap Jul 24, 2023
@glebfox glebfox changed the title Formatter for DataGrid columns Declarative renderers for DataGrid columns Jul 28, 2023
@rusiaikinat rusiaikinat self-assigned this Aug 1, 2023
@gorbunkov gorbunkov added this to the 2.1.0 milestone Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

4 participants