|
| 1 | +# Custom property value renderers |
| 2 | + |
| 3 | +Data in [PropertyGrid]($components-react) and [Table]($components-react) components is displayed by property value renderers. By defining and registering custom renderers, users can extend property rendering system to support new data types and UI interactions. |
| 4 | + |
| 5 | +A custom renderer can be used by assigning it to specific properties through a property override. See [`PropertySpecification.renderer` section](../Content/PropertySpecification.md#attribute-renderer) for an example. |
| 6 | + |
| 7 | +## Built-in renderers |
| 8 | + |
| 9 | +iTwin.js UI and presentation packages register some built-in value renderers that can be used out of the box. |
| 10 | + |
| 11 | +### `SelectableInstance` |
| 12 | + |
| 13 | +> **Component:** [InstanceKeyValueRenderer]($presentation-components) |
| 14 | +> |
| 15 | +> **Prerequisites:** |
| 16 | +> |
| 17 | +> - Property value type is [Primitives.InstanceKey]($appui-abstract). Generally those are navigation type of properties. |
| 18 | +> - The property is rendered within a unified selection context. See [useUnifiedSelectionContext]($presentation-components) for more details. |
| 19 | +
|
| 20 | +The renderer renders nothing when property value is `undefined`. When it's defined, the value is rendered as a clickable text. |
| 21 | + |
| 22 | +The property display value is used for the displayed text. If it is not set, then the [Type Converter](../../learning/ui/components/TypeConverters.md) system is used to calculate displayed string from the raw property value. |
| 23 | + |
| 24 | +When the clickable text clicked on, the available unified selection context is used to replace active selection with the instance key stored in the value by calling [UnifiedSelectionContext.replaceSelection]($presentation-components). |
| 25 | + |
| 26 | +| Default rendering | `SelectableInstance` rendering | |
| 27 | +| ---------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | |
| 28 | +|  |  | |
| 29 | + |
| 30 | +### `url` |
| 31 | + |
| 32 | +> **Component:** [UrlPropertyValueRenderer]($components-react) |
| 33 | +> |
| 34 | +> **Prerequisites:** |
| 35 | +> |
| 36 | +> - Property type is one of [StandardTypeNames.URL]($appui-abstract), [StandardTypeNames.String]($appui-abstract) or [StandardTypeNames.Text]($appui-abstract). |
| 37 | +> |
| 38 | +> **Default for:** Properties with [StandardTypeNames.URL]($appui-abstract) type name. Generally those are properties with `"URI"` extended type in ECSchema. |
| 39 | +
|
| 40 | +The renderer renders nothing when property value is `undefined`. When it's defined, the value is rendered as a clickable text. |
| 41 | + |
| 42 | +The property value is passed through the [Type Converter](../../learning/ui/components/TypeConverters.md) system to calculate displayed string. When the text clicked on, the user is navigated to the URL set to that text. **Note:** the renderer doesn't validate the text to really be a URL. |
| 43 | + |
| 44 | +| Default rendering | `url` rendering | |
| 45 | +| -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | |
| 46 | +|  |  | |
| 47 | + |
| 48 | +### `multiline` |
| 49 | + |
| 50 | +> **Component:** [MultilineTextPropertyValueRenderer]($components-react) |
| 51 | +> |
| 52 | +> **Prerequisites:** |
| 53 | +> |
| 54 | +> - Property value is of primitive type. |
| 55 | +
|
| 56 | +The renderer renders nothing when property value is `undefined`. When it's defined, the value is passed through the [Type Converter](../../learning/ui/components/TypeConverters.md) system to calculate displayed string. The string is rendered in a single line with ellipsis and is allowed to be expanded into multiple lines to fit the whole string. |
| 57 | + |
| 58 | +| Default rendering | `multiline` rendering | |
| 59 | +| -------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 60 | +|  |   | |
| 61 | + |
| 62 | +## Adding a custom renderer |
| 63 | + |
| 64 | +A new custom property value renderer can be added by registering a class implementing [IPropertyValueRenderer]($components-react) to the [PropertyValueRendererManager]($components-react): |
| 65 | + |
| 66 | +```tsx |
| 67 | +[[include:Content.Customization.PropertySpecification.Renderer.Register]] |
| 68 | +``` |
| 69 | + |
| 70 | +The renderer registered above is used whenever a property with that renderer name is being rendered. The below ruleset demonstrates assigning the renderer to a property: |
| 71 | + |
| 72 | +```ts |
| 73 | +[[include:Content.Customization.PropertySpecification.Renderer.Ruleset]] |
| 74 | +``` |
| 75 | + |
| 76 | + |
0 commit comments