Class: CellRenderer

CellRenderer

new CellRenderer()

Instances of CellRenderer are used to render the 2D graphics context within the bound of a cell.

Extend this base class to implement your own cell renderer.

Tutorials:

Methods

paint(gc, config) → {number}

An empty implementation of a cell renderer, see the null object pattern.

This:
Parameters:
Name Type Description
gc CanvasRenderingContext2D
config CellRenderer#renderConfig
Returns:

Preferred pixel width of content. The content may or may not be rendered at that width depending on whether or not config.bounds was respected and whether or not the grid renderer is using clipping. (Clipping is generally not used due to poor performance.)

Type
number

roundRect(gc, x, y, width, height, radius, fill, stroke)

A simple implementation of rounding a cell.

Parameters:
Name Type Description
gc CanvasRenderingContext2D
x number

the x grid coordinate of my origin

y number

the y grid coordinate of my origin

width number

the width I'm allowed to draw within

height number

the height I'm allowed to draw within

radius number
fill number
stroke number

Type Definitions

renderConfig

This is the renderer config object, which is:

  1. First passed to a getCell method implementation, which may override (most of) its values before returning.
  2. Then passed to the specified cell renderers' paint function for rendering.

Standard Properties

On each render of every visible cell, this a fresh instance of an object created from (whose prototype is) a properties object as defined by layer-props.js. It therefore has all the standard properties defined in module:defaults.

Additional Properties

In addition, the config object has the following additional properties.

Properties marked read-only may in fact be writable, but should be considered off limits to overriding. Do not attempt to change these properties inside a getCell method override.

Properties marked write-only are to be defined the cell renderer for use by the caller (the grid renderer).

Type:
  • object
Properties:
Name Type Attributes Description
config.allRowsSelected boolean
config.bounds BoundingRect

Bounding rect of the cell or subcell to be rendered.

config.clickRect object <optional>

Write-only. The Cell renderer may return in this property a subrect in the cell's local coordinates that represents a click region. If defined by the cell renderer, the CellClick feature will ignore clicks outside the click region. If not defined by the cell renderer, the entire cell is clickable.

config.dataCell dataCellCoords

Read-only. Data coordinates of the cell.

config.dataRow dataRowObject

Access to other column values in the same row.

config.formatValue function

For cell renderer use only. Not available in getCell override. The cell's value formatter function (based on the formatter name in config.format, as possibly mutated by getCell).

config.gridCell gridCellCoords

Read-only. Grid coordinates of the cell.

config.halign string

The cell's horizontal alignment property, as interpreted by it's cell renderer.

config.isCellHovered boolean

-

config.isCellSelected boolean

-

config.isColumnHovered boolean

-

config.isColumnSelected boolean

-

config.isDataColumn boolean

-

config.isDataRow boolean

-

config.isFilterRow boolean

-

config.isHandleColumn boolean

-

config.isHeaderRow boolean

-

config.isInCurrentSelectionRectangle boolean

-

config.isRowHovered boolean

-

config.isRowSelected boolean

-

config.isSelected boolean

-

config.isTreeColumn boolean

-

config.isUserDataArea boolean

-

config.minWidth number

Write-only. The Cell renderer should return the pixel width of the rendered contents in this property.

config.mouseDown boolean

The last mousedown event occurred over this cell and the mouse is still down. Note, however, that the mouse may no longer be hovering over this cell when it has been dragged away.

config.prefillColor <optional>

Write-only. This is the color already painted by the grid renderer behind the cell to be rendered. If the cell's specified background color is the same, renderer may (and should!) skip painting it. If undefined, this signals a "partial render"; cell renderers that support partial rendering can use config.snapshot to determine whether or not to rerender the cell.

config.snapshot object <optional>

Write-only. Supports partial render. In support of the by-cells "partial" grid renderer, cell renderers can save the essential render parameters in this property so that on subsequent calls, when the parameters are the same, cell renderers can skip the actual rendering. Only when the parameters have changed is the cell rendered and this property reset (with the new parameters). This object would typically include at the very least the (formatted) value, plus additional properties as needed to fully describe the appearance of the render, such as color, etc. This property is undefined the first time a cell is rendered by the by-cells grid renderer. See also the DataModel#configObject's prefillColor property.

config.value

Value to be rendered.

The renderer has available to it the .formatValue() function for formatting the value. The function comes from the localizer named in the .format property. If there is no localizer with that name, the function defaults to the string localizer's formatter (which simply invokes the value's toString() method).

Typically a Local primitive value, values can be any type, including objects and arrays. The specified cell renderer is expected to know how to determine the value's type and render it.