The field
property of columns in LyteNyte Grid determines the cell value for a given row in
a specific column.
LyteNyte Grid supports four types of values for the field
property:
string
value: Used when row data is an object. The string serves as a key to look up the value.number
value: Used when row data is an array. The number acts as an index into the data array.function
callback: Used for custom calculations of a column's field value.{ kind: 1; path: string }
: Used for accessing nested values in object data.
The kind
property must be set to 1, and the path
must be a string indicating the path to follow.This guide explains how to use each field type in detail.
The field
property is the primary field property on a column, but there are others:
groupField
: Calculates the group key when columns are used for row groupsinFilterField
: Calculates the in-filter value of a column for a given rowquickSearchField
: Calculates the quick search filter valueThe field
property serves as the fallback for all other field calculators. All field calculators
accept the same set of values - they only differ in how their output is used.
The field
property is optional. When not provided, the column's id
is used as a fallback.
When the field
property is a string
, it works as a key lookup value. The row data is expected
to be an object, and the field string is used as a key to access the value:
If no field
property is provided for a column, the column's id
is used as a fallback.
Since column id
must be a string, this fallback implicitly functions as a key lookup field.
When the field
property is a number
, the row data is expected to be an array. The number
serves as an index in the array to retrieve the cell value. This approach is particularly useful
when working with array data.
The field
property can accept a function as its value. Function fields offer the most flexibility
among all field types, allowing for arbitrary calculations. They are especially useful when a
column's value depends on values from other columns.
A field
can specify a path to a value using the form { kind: 1; path: string }
. The kind: 1
tells LyteNyte Grid to use a path calculator, while the path
property specifies the path to the
value, typically for accessing nested values in an object.
The syntax for the path
string is similar to Lodash's get
function. Examples include:
{ kind: 1, path: "alpha.beta[0]" };
{ kind: 1, path: "beta[0].alpha" };
We generally recommend using either string
or number
fields. Number fields provide the most
compact data representation since data lookup is ordinal. Function and path fields tend to
introduce higher complexity. Additionally, function fields prevent columns from being serializable,
which may be undesirable in certain scenarios.