Global

Members

assignProps

Overridable for alternative or faster logic.

cellEventFactory

Create a custom CellEvent class.

Create a custom definition of CellEvent for each grid instance, setting the grid, behavior, and dataModel properties on the prototype. As this happens once per grid instantiation, it avoids having to perform this set up work on every CellEvent instantiation.

registry

The Hypergrid theme registry.

The standard registry consists of a single theme, default, built from values in defaults.js.

visibleColumns :visibleColumnArray

Represents the ordered set of visible columns. Array size is always the exact number of visible columns, the last of which may only be partially visible.

This sequence of elements' columnIndex values assumes one of three patterns. Which pattern is base on the following two questions:

  • Are there "fixed" columns on the left?
  • Is the grid horizontally scrolled?

The set of columnIndex values consists of:

  1. The first element will be -1 if the row handle column is being rendered.
  2. A zero-based list of consecutive of integers representing the fixed columns (if any).
  3. An n-based list of consecutive of integers representing the scrollable columns (where n = number of fixed columns + the number of columns scrolled off to the left).
Type:

visibleRows :visibleRowArray

Represents the ordered set of visible rows. Array size is always the exact number of visible rows.

The sequence of elements' rowIndex values is local to each subgrid.

  • For each non-scrollable subgrid: The sequence is a zero-based list of consecutive integers.
  • For the scrollable subgrid:
    1. A zero-based list of consecutive of integers representing the fixed rows (if any).
    2. An n-based list of consecutive of integers representing the scrollable rows (where n = number of fixed rows + the number of rows scrolled off the top).

Note that non-scrollable subgrids can come both before and after the scrollable subgrid.

Type:

Methods

addAllColumnProperties(columnsHash, settingStateopt)

Adds properties for multiple columns.

Adds . The properties collection is optionally cleared first. Falsy elements are ignored.

Parameters:
Name Type Attributes Description
columnsHash Array.<object> | undefined

If undefined, this call is a no-op.

settingState boolean <optional>

Clear columns' properties objects before copying properties.

cancelEditing() → {boolean}

Cancels editing.

Returns:

Successful. (Cancel is always successful.)

Type
boolean

computeCellsBounds()

This function creates several data structures:

  • Renderer#visibleColumns
  • Renderer#visibleRows

Original comment: "this function computes the grid coordinates used for extremely fast iteration over painting the grid cells. this function is very fast, for thousand rows X 100 columns on a modest machine taking usually 0ms and no more that 3 ms."

This:

createColumns()

This:

createDataRowProxy()

Build the $rowProxy$ lazy getter collection based on current schema.

The $rowProxy$ lazy getter collection is returned by the getRow fallback.

$rowProxy$ collection is a dataRow-like object (a hash of column values keyed by column name) for the particular row whose index is in the $y$ property.

The row index can be conveniently set with a call to fallbacks.getRow(), which sets the row index and returns the accessor itself.

$y$ is a "hidden" property, non-enumerable it won't show up in Object.keys(...).

This fallback implementation is "lazy": The enumerable members are all getters that invoke getValue and setters that invoke setValue.

This function should be called each time a new schema is set.

deferredBehaviorChange()

Called from renderer/index.js

deprecated(methodName, dotProps, since, argsopt, notesopt) → {*}

User is warned and new property is returned or new method is called and the result is returned.

Parameters:
Name Type Attributes Description
methodName string

Warning key paired with arbitrary warning in dotProps OR deprecated method name with parentheses containing optional argument list paired with replacement property or method in dotProps.

dotProps string

Arbitrary warning paired with warning key in methodName OR dot-separated new property name to invoke or method name to call. Method names are indicated by including parentheses with optional argument list. The arguments in each list are drawn from the arguments presented in the methodName parameter.

since string

Version in which the name was deprecated.

args Arguments | Array <optional>

The actual arguments in the order listed in methodName. Only needed when arguments need to be forwarded.

notes string <optional>

Notes to add to message.

Returns:

Return value of new property or method call.

Type
*

dispatchDataModelEvent(event)

Hypergrid data model event handler.

This function is not called by Hypergrid. Rather, it is handed to the data model (by injectCode as dispatchEvent) to issue callbacks to the grid.

This handler:

  1. Checks the event string to make sure it conforms to the expected syntax:
    • Starts with fin-hypergrid-data- or fin-hypergrid-schema-
    • Includes only lowercase letters and hyphens
  2. Calls a handler in the dataModelEventHandlers namespace of the same name as the event string.
  3. Re-emits the event as a DOM event to the <canvas> element (unless the handler has already done so).

The data model's dispatchEvent method is bound to the grid by injectCode. A bound version of this function, bound to the grid instance, is either:

  • Added to the data model via its addListener method, if it has one; or
  • Force-injected into the data model, overriding any native implementation. (A native implementation may exist simply to "catch" calls that might be made before the data model is attached to Hypergrid.)
This:
Parameters:
Name Type Description
event string | NormalizedDataModelEvent

errorEffectEnd(erroropt)

This function expects to be passed an error. There is no point in calling this function if there is no error. Nevertheless, if called with a falsy error, returns without doing anything.

This:
Parameters:
Name Type Attributes Description
error boolean | string | Error <optional>

findCell(colIndexOrCellEvent, rowIndexopt, dataModelopt) → {CellEvent}

Parameters:
Name Type Attributes Default Description
colIndexOrCellEvent number | CellEvent

This is the "data" x coordinate.

rowIndex number <optional>

This is the "data" y coordinate. Omit if colIndexOrCellEvent is a CellEvent.

dataModel DataModel <optional>
this.grid.behavior.dataModel

Omit if colIndexOrCellEvent is a CellEvent.

Returns:

The matching CellEvent object from the renderer's pool. Returns undefined if the requested cell is not currently visible (due to being scrolled out of view).

Type
CellEvent

getActiveColumns(beginopt, endopt)

Parameters:
Name Type Attributes Description
begin number <optional>
end nubmer <optional>
  • @returns {Column[]} A copy of the active columns array by passing the params to Array.prototype.slice.

getColumns(beginopt, endopt)

Parameters:
Name Type Attributes Description
begin number <optional>
end nubmer <optional>
  • @returns {Column[]} A copy of the all columns array by passing the params to Array.prototype.slice.

getMinimumLeftPositionToShowColumn(targetColIdx) → {number}

Calculate the minimum left column index so the target column shows up in viewport (we need to be aware of viewport's width, number of fixed columns and each column's width)

Parameters:
Name Type Description
targetColIdx number

Target column index

Returns:

Minimum left column index so target column shows up

Type
number

getSubrects()

Create a list of Rectangles representing visible cells.

When grid.properties.fetchSubregions is true, this function needs to handle:

  1. unordered columns
  2. column gaps (hidden columns)
  3. the single row gap that results when there are fixed rows and remaining rows are scrolled down
This:
To Do:
  • This function currently only handles (1) above; needs (2) (multiple rectangles for multiple contiguous column regions) and (3) (double each region for above and below the fixed boundary when scrolled down) as well. In its present form, it will "fetch" all cells from upper left of fixed area to lower right of scrollable area. (Yikes.) When `grid.properties.fetchSubregions` is falsy, this function merely returns `this.dataWindow` as the only rectangle. This is way more efficient than calling `getSubrects` (as it is currently implemented) and is fine so long as there are no fixed columns or rows and column re-ordering is disabled. (If tree column in use, it is a fixed column, but this is workable so long as the data model knows to always return it regardless of rectangle.) Hidden columns within the range of visible columns will be fetched anyway. Column scrolling is ok.
  • This function is too slow for practical use due to map and sort.

getTextWidthTruncated(gc, string, width, truncateTextWithEllipsis, abortopt) → {Object}

Similar to getTextWidth except:

  1. Aborts accumulating when sum exceeds given width.
  2. Returns an object containing both the truncated string and the sum (rather than a number primitive containing the sum alone).
Parameters:
Name Type Attributes Default Description
gc CanvasRenderingContext2D
string string

Text to measure.

width number

Width of target cell; overflow point.

truncateTextWithEllipsis boolean | null | undefined

Per module:defaults.truncateTextWithEllipsis.

abort boolean <optional>
false

Abort measuring upon overflow. Returned width sum will reflect truncated string rather than untruncated string. Note that returned string is truncated in either case.

Returns:
  • object.string - undefined if it fits; truncated version of provided string if it does not.
  • object.width - Width of provided string if it fits; width of truncated string if it does not.
Type
Object

getVisibleCellMatrix() → {Array.<Array>}

Matrix of unformatted values of visible cells.

Returns:
Type
Array.<Array>

handleKeyDown()

Navigate away from the filter cell when:

  1. Coming from a cell editor (event.detail.editor defined).
  2. The cell editor was for a filter cell.
  3. The key (`event.detail.char) maps (through navKeyMap) to one of:
    • 'UP' or 'DOWN' - Selects first visible data cell under filter cell.
    • 'LEFT' - Opens filter cell editor in previous filterable column; if nonesuch, selects first visible data cell under filter cell.
    • 'RIGHT' - Opens filter cell editor in next filterable column; if nonesuch, selects first visible data cell under filter cell.

rebundleGridRenderers()

Certain renderers that pre-bundle column rects based on columns' background colors need to re-bundle when columns' background colors change. This method sets the rebundle property to true for those renderers that have that property.

resetCellPropertiesCache(xOrCellEvent, yopt, dataModelopt) → {CellEvent}

Resets the cell properties cache in the matching CellEvent object from the renderer's pool. This will insure that a new cell properties object will be known to the renderer. (Normally, the cache is not reset until the pool is updated by the next call to Renderer#computeCellBounds).

Parameters:
Name Type Attributes Default Description
xOrCellEvent number | CellEvent
y number <optional>
dataModel DataModel <optional>
this.grid.behavior.dataModel
Returns:

The matching CellEvent object.

Type
CellEvent

resetRowHeaderColumnWidth(gc, rowCount)

Resize the handle column.

Handle column width is sum of:

  • Width of text the maximum row number, if visible, based on handle column's current font
  • Width of checkbox, if visible
  • Some padding
This:
Parameters:
Name Type Description
gc CanvasRenderingContext2D
rowCount number

resolveCalculator(calculator) → {function}

Calculators are functions. Column calculators are saved in grid.properties.calculators using the function name as key. Anonymous functions use the stringified function itself as the key. This may seem pointless, but this achieves the objective here which is to share function instances.

This:
Parameters:
Name Type Description
calculator function | string

One of:

  • calculator function
  • stringified calculator function with or without function name
  • function name of a known function (already in calculators)
  • falsy value
Throws:
  • Unexpected input.

    Type
    HypergridError
  • Arrow function not permitted.

    Type
    HypergridError
  • Unknown function.

    Type
    HypergridError
Returns:

Shared calculator instance or undefined if input was falsy.

Type
function

setAllColumnProperties(columnsHash)

Sets properties for active columns.

Sets multiple columns' properties from elements of given array or collection. Keys may be column indexes or column names. The properties collection is cleared first. Falsy elements are ignored.

Parameters:
Name Type Description
columnsHash Array.<object> | undefined

If undefined, this call is a no-op.

valOrFunc(column) → {string}

This:
Parameters:
Name Type Description
column
Returns:
Type
string

Type Definitions

BoundingRect

A bounding rectangle.

Properties:
Name Type Description
x number

Horizontal coordinate of upper-left corner of bounding rect.

y number

Vertical coordinate of upper-left corner of bounding rect.

width number

Width of bounding rect.

height number

Height of bounding rect.

CanvasRenderingContext2D

Type:
  • object
See:

columnSchema

Type:
  • object
Properties:
Name Type Attributes Default Description
name string
header string <optional>
name
index number
type string <optional>
calculator string <optional>

dataCellCoords

Type:
Properties:
Name Type Description
x number

The data model's column index, unaffected by column scrolling; i.e., an index suitable for dereferencing the column object to which the cell belongs via Behavior#getColumn.

y number

The data model's row index, adjusted for data row scrolling after fixed rows.

DataModelEvent

Besides type, your event object can contain other event details.

After calling the internal handler found in src/behaviors/Local/events.js matching the event name, Hypergrid then creates a CustomEvent with the same name, sets its detail property to this object, and dispatches to the <canvas> element — to be picked up by any listeners previously attached with Hypergrid#addEventListener.

Type:
  • object

DataModelListener(event)

This:
Parameters:
Name Type Description
event DataModelEvent

dataRowObject

A data row representation. The properties of this object are the data fields. The property keys are the column names. All row objects should be congruent, meaning that each data row should have the same property keys.

Type:
  • object

gridCellCoords

Type:
Properties:
Name Type Description
x number

The active column index, adjusted for column scrolling after fixed columns; i.e., an index suitable for dereferencing the column object to which the cell belongs via Behavior#getActiveColumn.

y number

The vertical grid coordinate, unaffected by subgrid, row scrolling, and fixed rows.

NormalizedDataModelEvent

Type:
  • object
Properties:
Name Type Description
type string

Event string.

pluginSpec()

One of:

  • simple API - a plain object with an install method
  • object API - an object constructor
  • array:
    • first element is an optional name for the API or the newly instantiated object
    • next element (or first element when not a string) is the simple or object API
    • remaining arguments are optional arguments for the object constructor
  • falsy value such as undefined - ignored

The API may have a name or $$CLASS_NAME property.

Point

See:

rawColumnSchema

Column schema may be expressed as a string primitive on input to setData.

Type:

Rectangle

See:

subgridConstructorRef

Type definition.

One of:

  • function type - Assumed to already be a data model constructor.
  • string type - The name of a data model "class" (constructor) registered in the src/dataModels namespace. Used to look up the constructor in the namespace.

subgridSpec

Type definition.

One of:

  • object type (except when an array) - Assumed to be a reference to an already-instantiated data model. Used as is.
  • 'data' special value - Set to the data subgrid (i.e., the behavior's already-instantiated data model).
  • subgridConstructorRef (see) - The constructor ref is resolved and called with the new keyword + a reference to the grid as the sole parameter.
  • Array object — Accommodates data model constructor arguments. The constructor ref is resolved and called with the new keyword + a reference to the grid as the first parameter + the remaining elements as additional parameters. (If you don't have remaining elements, don't give an array here; just provide a simple subgridConstructorRef instead.) The array should have two or more elements:
    • The first element is a subgridConstructorRef.
    • Remaining elements are used as additional parameters to the constructor.

visibleColumnArray

Type:
  • object
Properties:
Name Type Description
index number

A back reference to the element's array index in Renderer#visibleColumns.

columnIndex number

Dereferences Behavior#columns, the subset of active columns, specifying which column to show in that position.

left number

Pixel coordinate of the left edge of this column, rounded to nearest integer.

right number

Pixel coordinate of the right edge of this column, rounded to nearest integer.

width number

Width of this column in pixels, rounded to nearest integer.

visibleRowArray

Type:
  • object
Properties:
Name Type Description
index number

A back reference to the element's array index in Renderer#visibleRows.

rowIndex number

Local vertical row coordinate within the subgrid to which the row belongs, adjusted for scrolling.

subgrid DataModel

A reference to the subgrid to which the row belongs.

top number

Pixel coordinate of the top edge of this row, rounded to nearest integer.

bottom number

Pixel coordinate of the bottom edge of this row, rounded to nearest integer.

height number

Height of this row in pixels, rounded to nearest integer.