-
Notifications
You must be signed in to change notification settings - Fork 144
Cell Values
The value of an individual grid cell (a particular field in a particular data row) is typically a JavaScript primitive value.
A cell value can, however, be any kind of object, subject to the cell renderer's ability to interpret that object.
For example, a sparkline cell renderer might expect to find an array of numbers.
A cell value can even be an instantiated object, including a function — although this will require some riviving if the source of your data is JSON.
When a cell value is a function, it is called a computed cell or computed value; the function itself is called the cell's calculator.
How a cell value is computed depends entirely on the cell renderer.
For greater performance, the cell renderer can make assumptions about the cell value, assuming for example that it is always a calculator, or assuming that it is never a calculator.
A more flexible (but less performant) cell renderer will however follow this general algorithm:
- If the cell has its own calculator, call it.
- Otherwise, if the column has a calculator, call it.
- Otherwise, use the cell value as is.
This common algorithm is provided in a function on the config
object passed to the cell renderer:
function myCellRenderer(gc, config) {
var value = config.exec(config.value);
//code to render `value` goes here
}
exec
calls the calculator in a standard way (see Calculator Calling Conventions, below).
A standard is necessary if your data model performs any data analytics, by which we mean observing the values in cells. A data model that simply returns the data does no analytics. But a data model that provides any additional services, such as filtering or sorting on the client, will need to compare values between rows, and therefore will need to know how to call calculators, when present, to get those values.
The data model has very limited information about the cell, including only the cell's data coordinates, column name, type, and calculator. Unlike the cell renderer, it may not make any assumptions, and therefore always needs to check for a calculator, and if found needs to call it on its own, using the same calling convention as the cell renderers.
The standard calculator calling convention, as embodied by Hypergrid.defaults.exec
, consists of two parameters:
- A hash containing all the values of all the columns in the current grid row (keyed by column name)
- A string containing the name of the present column
You are free to choose a different standard for your calling convention; but if your data model performs any analytics, it must use the same standard. You can easily override exec
(owned by the Hypergrid.defaults
object), but note that the config
object, including config.exec
, is only useful for rendering. It is constructed at render time to reflect the specific cell being rendered and is not applicable to other cells. It is made available to the cell renderer only but is never available to the data model.