Skip to content

docs: add Grid Lit renderer link and image, sorting, and map item examples - #6184

Merged
peholmst merged 7 commits into
mainfrom
docs/grid-columns-renderers-examples
Dec 2, 2026
Merged

peholmst merged 7 commits into
mainfrom
docs/grid-columns-renderers-examples

Conversation

@totally-not-ai

@totally-not-ai totally-not-ai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review risk: two-way door: docs only. It adds sections to three Grid pages and one demo class, and changes no existing content.

Summary

Adds Grid examples for rendering links and images with Lit renderers, sorting columns that use renderers, and using maps as Grid items with the inline editor.

What changed

  • Renderers (renderers.adoc): a new section, "Rendering Links & Images in Lit Renderers". It covers route links whose URL is built with RouteConfiguration, and <img> tags with alt text. For links that should run server-side code, it points to rendering a button and handling its click.
  • Sorting (index.adoc, Flow only): explains that renderer-based columns, and columns that show numbers as strings, need setComparator() to sort correctly with in-memory data, and that lazy data providers use setSortProperty() and sort in the fetch callback instead.
  • Data binding (data-binding.adoc): a new section, "Binding Maps Instead of Beans". It uses a new demo, BindingMapItems, which builds its columns at runtime and uses an inline Editor with a Binder. It also explains why setIdentifierProvider is needed when map items are edited.

Test summary

  • The BindingMapItems demo compiles and passes the format check. The other examples are inline snippets.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Preview Deployment

This PR has been deployed for preview.

URL: https://docs-preview-pr-6184.fly.dev

Changed pages

Added content is highlighted in green; removed content is marked in red on each page.

Built from a5fdcfb

Comment thread articles/components/grid/columns.adoc Resolved
@totally-not-ai totally-not-ai Bot changed the title docs: add Grid link, image, responsive column, and map item examples docs: add Grid link, image, and map item examples Sep 29, 2026
vursen added a commit that referenced this pull request Sep 29, 2026
…6199)

Adds an example to the **Column Visibility** part of
`articles/components/grid/columns.adoc`. It hides the individual columns
and shows a single combined column when the Grid is narrow, and switches
back when it's wide.

The example is available for all three frameworks and renders inside a
Split Layout, so readers can drag the handle to resize the Grid:
- **Flow** (`GridResponsiveColumns.java`): reacts to the Grid's own size
through `getElement().sizeSignal()` inside a `Signal.effect`. A width of
0 (before the browser reports the size) is treated as wide.
- **Lit** (`grid-responsive-columns.ts`) and **React**
(`react/grid-responsive-columns.tsx`): use a `ResizeObserver` on the
Grid.
- A note explains that the Flow size signal starts at 0, so the layout
can briefly flash, and mentions the window size signal as an alternative
with a known initial value.
- `frontend/demo/example-resources.ts` imports `ElementResize.js` as a
temporary workaround for vaadin/flow#26041, so the size signal works in
exported demos.

This change was split out of #6184.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com>
Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
totally-not-ai Bot and others added 3 commits October 5, 2026 13:26
Add examples for rendering links and images in Grid cells, formatting
numbers with the user's locale, sorting renderer-based columns,
responsive column visibility, and using maps as Grid items with an
inline editor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This reverts commit 21ed0ce914d6d0f9afeef6f27bea62e2ed3d1e3d.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@vursen
vursen force-pushed the docs/grid-columns-renderers-examples branch from 284ae79 to a762411 Compare October 5, 2026 09:28
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
vursen added a commit that referenced this pull request Oct 5, 2026
**Previous approach:** #6184 proposed a dedicated `NumberRenderer`
example that creates the currency format with the UI locale,
`NumberFormat.getCurrencyInstance(UI.getCurrentOrThrow().getLocale())`,
together with a note that a `NumberFormat` created without a locale uses
the default locale of the server and a link to the Language Selection
page (see [the paragraph in
#6184](https://github.com/vaadin/docs/blob/a7624115fa335bed10c82e413b995f21e97d8597/articles/components/grid/renderers.adoc#L132-L142)).
The UI locale is wrong for that example. `getCurrencyInstance(locale)`
takes the currency from the locale, so the same price would render as
`$1,234.56` for a US user and as `1 234,56 €` for a Finnish user. A
price is an amount in one specific currency, so its currency symbol must
not change with the user's locale.

**This PR:** Each example passes the locale that fits what it formats:

- The two `FormatStyle` date examples use
`UI.getCurrentOrThrow().getLocale()`. Here the locale only changes how
the same date is presented, which is what localized formats are for. The
text says the date is rendered in the format specified by the UI locale,
and a link to Language Selection follows each example.
- The two number examples use `Locale.US`, because both render a price
in US dollars: the currency format takes the currency from the locale,
and the string format hardcodes `$`. Their lead-in sentences say so.
- The string-pattern date examples (`dd/MM/yyyy` and `dd/MM HH:mm:ss`)
stay as they are, because the locale has no effect on digit-only
patterns.

Extracted from #6184.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Comment thread articles/components/grid/renderers.adoc Outdated
Comment on lines +280 to +291
To show an image that's stored as a byte array -- for example, a profile picture loaded from a database -- use an [classname]`Image` component. The image data is served to the browser through a download handler instead of being embedded in the grid data:

[source,java]
----
grid.addComponentColumn(person -> {
Image image = new Image(person.getPicture(), "Profile picture");
image.setHeight("48px");
return image;
}).setHeader("Picture");
----

When the image data of an item changes, call [methodname]`refreshItem()` on the grid's data provider to render the new image. If the image is available through a URL, a Lit renderer is a more lightweight alternative. See <<rendering-links-and-images-in-lit-renderers,Rendering Links & Images in Lit Renderers>> for an example.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@totally-not-ai Let's extract this change into a separate PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vursen Done. The byte-array image example is now in its own PR, #6264, and I removed it from this one. In #6264 the closing sentence links to the existing Lit Renderer section, because the "Rendering Links & Images in Lit Renderers" section exists only in this PR. I also updated this PR's title and description to match what's left.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@totally-not-ai totally-not-ai Bot changed the title docs: add Grid link, image, and map item examples docs: add Grid Lit renderer link and image, sorting, and map item examples Oct 5, 2026
@peholmst
peholmst marked this pull request as ready for review November 4, 2026 13:01

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes — left 3 comments.

Finding
⚠️ The new sorting advice recommends setComparator() without saying it only works with in-memory data.
💬 The "for more information" link about setIdentifierProvider points to a section that never mentions it.
🧩 The snippet tag starts after the data setup, so the included code uses undefined variables.

--

ifdef::flow[]
In Flow, columns created from a value provider -- for example, `grid.addColumn(Person::getAge)` -- are sorted by the provided value when using in-memory data. Columns created with a renderer, such as [classname]`LitRenderer`, [classname]`ComponentRenderer`, or [classname]`NumberRenderer`, don't have a value to sort by. They don't sort items unless you define a comparator with [methodname]`setComparator()`. Similarly, a column that renders numbers as formatted strings sorts them alphabetically unless you define a comparator:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ The new sorting advice recommends setComparator() without saying it only works with in-memory data.

They don't sort items unless you define a comparator with setComparator().

Column.setComparator() has no effect when the Grid uses a lazy data provider — see the javadoc in Grid.java (vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/Grid.java:838-845): "the comparator is only used with in-memory data providers ... In that case, define the sort properties with setSortProperty(String...)". Lazy loading is documented on the same page (== Lazy Loading), so a reader there follows this advice and nothing happens.

The first sentence scopes "in-memory" to value-provider columns only, so the scope doesn't carry over. Suggested addition after the snippet:

Comparators apply only to in-memory data. With a lazy data provider, define the sorting with setSortProperty() instead and implement it in the data provider.

articles/flow/binding-data/data-provider.adoc:524 already makes this distinction and has an anchor to link to (data-binding.data-provider.lazy-sorting).

index.adoc:211 · accuracy

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, added a note after the snippet: comparators apply only to in-memory data. With a lazy data provider, set a sort property with setSortProperty() and apply it in the fetch callback, where it arrives in query.getSortOrders(), with a link to the lazy data binding section that shows backend sorting.


--

The equality and hash code of a map depend on its content, which changes when an item is edited. Therefore, the example uses `setIdentifierProvider` to identify each item by a stable key. See <<{articles}/flow/binding-data/data-provider#data-binding.data-provider.item-identifiers,Item Identifiers>> for more information.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 The "for more information" link about setIdentifierProvider points to a section that never mentions it.

the example uses setIdentifierProvider to identify each item by a stable key. See <<...#data-binding.data-provider.item-identifiers,Item Identifiers>> for more information.

The target section is articles/flow/binding-data/data-provider.adoc:737, titled "Stable & Unique Item Identities". It covers only implementing equals() and hashCode() on a Java class, which is exactly what a reader using HashMap items cannot do. setIdentifierProvider appears nowhere else in articles/, so the reader who follows the link for more information finds none.

The link text also doesn't match the target heading.

Consider either dropping the cross reference or describing the method inline, for example what IdentifierProvider affects (the Grid's key mapper) and that it must be set on the data view returned by setItems().

data-binding.adoc:111 · clarity

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped the cross-reference, since the target section only covers equals()/hashCode(). The paragraph now explains it inline: setIdentifierProvider() is called on the data view returned by setItems(), and the Grid uses that identifier instead of equals()/hashCode() to track items, so editing and refreshing keep working after an item's content changes.

rows.add(row);
}

// tag::body[]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 The snippet tag starts after the data setup, so the included code uses undefined variables.

tags=body begins at Grid<Map<String, Object>> grid = new Grid<>();, so the rendered snippet references rows and months with no definition, and the shape of the item map (the "product" key, month names as keys) is invisible. The lambdas row.get("product") and row.get(month) are the point of the example, and the reader can't see what they read from.

The sibling examples on the same page do it the other way: BindingInMemoryList puts the item construction inside tag::body, and the page additionally includes Person.java as a second source block.

Moving the months and rows setup inside the tag would fix it.

BindingMapItems.java:26 · examples

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved tag::body up so the included snippet now starts with the months list and the rows setup, which shows the item map's shape (the "product" key and month-name keys).

@peholmst
peholmst requested a review from vursen November 6, 2026 09:08
@peholmst
peholmst merged commit f5c4db1 into main Dec 2, 2026
13 checks passed
@peholmst
peholmst deleted the docs/grid-columns-renderers-examples branch December 2, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants