Cell renderers
Linz tries to provide as many customisation options as possible. One of those is in the form of a what we call a cell renderer.
Cell renderers can be used within record overviews and model indexes. They're used to represent data to the user in a human friendly way.
You can do many things with cell renderers that will improve the user experience. For example, you could take latitude and longitude values and render a map, providing visual context about location information specific to the record.
Built-in cell renderers#
There are already many built-in cell renderers. They can all be accessed in the following namespace linz.formtools.cellRenderers.
The following shows how to define a specific cell renderer for a list field:
The following provides a description of each built-in cell renderer:
dateused withdatefield types to render a date, as per thedate formatsetting.overviewLinkcan be used to provide a link in the list, to the overview for a particular record.arraycan be used to format an array in the formatvalue 1, value 2, value 3.booleancan be used to format a boolean in the formatYesorNo.referencecan be used to render the title for areffield type.urlcan be used withurlfield types to render an<a>tag linking to the URL stored as the value of the field.documentarraycan be used with an embedded document to render a table showing embedded documents.textcan be used to render text, or any value as it is.defaultis used by Linz as the default cell renderer if a specific type can't be matched. It attempts to support arrays, dates, numbers, booleans and url field types.
Custom cell renderers#
You can quite easily create and use your own cell renderer. All cell renderers must have the same signature:
The value is the value that needs to be rendered. The record is a copy of the entire record that the value belongs to. The fieldName is the name of the field that is being rendered. The model is a reference to the model that the record belongs to.
The callback is a function that accepts the standard Node.js callback signature:
The result should be HTML. The HTML will be used directly, without manipulation. As it is HTML, you can provide inline JavaScript and CSS as required to add functionality your cell renderer.
The following is an example of a cell renderer that will look up data for a reference field and render the title: