Skip to main content

Rich content and client-side rendering

Tables in webforJ are also configurable using the following tools to display rich content within cells. This includes interactive components or formatted data within the table cells.

These elements are rendered client-side, meaning the process of generating and displaying rich content is done directly in the browser, using JavaScript only when needed, increasing performance of applications using the Table.

Lodash renderers

Renderers offer a powerful mechanism for customizing the way data is displayed within a Table. The primary class, Renderer, is designed to be extended to create custom renderers based on lodash templates, enabling dynamic and interactive content rendering.

Lodash templates enable the insertion of HTML directly into table cells, making them highly effective for rendering complex cell data in a Table. This approach allows for the dynamic generation of HTML based on cell data, facilitating rich and interactive table cell content.

Lodash syntax

The following section outlines the basics of Lodash syntax. While this is not an exhaustive or comprehensive overview, it can be used to help start using Lodash within the Table component.

Syntax overview for lodash templates:

  • <%= ... %> - Interpolates values, inserting the JavaScript code's result into the template.
  • <% ... %> - Executes JavaScript code, allowing loops, conditionals, and more.
  • <%- ... %> - Escapes HTML content, ensuring interpolated data is safe from HTML injection attacks.

Examples using cell data:

1. Simple value interpolation: Directly display the cell's value.

<%= cell.value %>

2. Conditional rendering: Use JavaScript logic to conditionally render content.

<% if (cell.value > 100) { %> 'High' <% } else { %> 'Normal' <% } %>

3. Combining data fields: Render content using multiple data fields from the cell.

<%= cell.row.getValue('firstName') + ' ' + cell.row.getValue('lastName') %>

4. Escaping HTML content: Safely render user-generated content.

The renderer has access to detailed cell, row, and column properties in the client side:

TableCell Properties:

PropertyTypeDescription
columnTableColumnThe associated column object.
firstbooleanIndicates if the cell is the first in the row.
idStringThe cell ID.
indexintThe cell's index within its row.
lastbooleanIndicates if the cell is the last in the row.
rowTableRowThe associated row object for the cell.
valueObjectThe raw value of the cell, directly from the data source.

TableRow Properties:

PropertyTypeDescription
cellsTableCell[]The cells within the row.
dataObjectThe data provided by the application for the row.
evenbooleanIndicates if the row is even-numbered (for styling purposes).
firstbooleanIndicates if the row is the first in the table.
idStringUnique ID for the row.
indexintThe row index.
lastbooleanIndicates if the row is the last in the table.
oddbooleanIndicates if the row is odd-numbered (for styling purposes).

TableColumn Properties:

PropertyTypeDescription
alignColumnAlignmentThe alignment of the column (left, center, right).
idStringThe field of the row object to get the cell's data from.
labelStringThe name to render in the column header.
pinnedColumnPinDirectionThe pin direction of the column (left, right, auto).
sortablebooleanIf true, the column can be sorted.
sortSortDirectionThe sort order of the column.
typeColumnTypeThe type of the column (text, number, boolean, etc.).
minWidthnumberThe minimum width of the column in pixels.

Available renderers

While custom renderers can be created, there are multiple pre-configured renderers available for use within a Table. The following are available for developers to use out of the box without the need to create a custom renderer:

  • ButtonRenderer - Renderer for a webforJ button.
  • NativeButtonRenderer - Renderer for a native HTML button.
  • ElementRenderer - The base class for all renderers which render an HTML tag with content.
  • VoidElementRenderer - The base class for all renderers which render a void element, or an HTML tag without content.
  • IconRenderer - Renderer for an icon - see this article for more information on icons.

Renderers allow for custom events to be written as well by extending any of the supported base renderer. Currently, renderers come with a RendererClickEvent available for use by developers.

Below is an example of a Table that uses renderers to display rich content:

Show Code