React Data GridCellRange

Description

The CellRange class holds a set of cell coordinates (CellCoords instances) that form a selection range.

A single CellRange instance represents a single unit of selection that contains either a single cell or multiple adjacent cells.

To import the CellRange class:

import Handsontable, { CellRange } from '/handsontable';

// or, using modules
import Handsontable, { CellRange } from '/handsontable/base';

Methods

clone

Source code

cellRange.clone() ⇒ CellRange

Clones your CellRange instance.

containsHeaders

Source code

cellRange.containsHeaders() ⇒ boolean

Checks if your range overlaps headers range (negative coordinates).

expand

Source code

cellRange.expand(cellCoords) ⇒ boolean

Adds a cell to your range, at cellCoords coordinates.

The cellCoords coordinates must exceed a corner of your range.

Param Type Description
cellCoords CellCoords A new cell's coordinates.

expandByRange

Source code

cellRange.expandByRange(expandingRange, [changeDirection]) ⇒ boolean

Expand your range with another range (expandingRange).

Param Type Default Description
expandingRange CellRange A new range.
[changeDirection] boolean true optional If true, the direction of your range is changed to the direction of the expandingRange range.

flipDirectionHorizontally

Source code

cellRange.flipDirectionHorizontally()

Flips the direction of your range horizontally (e.g., NW-SE changes to NE-SW).

flipDirectionVertically

Source code

cellRange.flipDirectionVertically()

Flips the direction of your range vertically (e.g., NW-SE changes to SW-NE).

forAll

Source code

cellRange.forAll(callback)

Runs a callback function on all cells within your range.

You can break the iteration by returning false in the callback function.

Param Type Description
callback function A callback function.

getAll

Source code

cellRange.getAll() ⇒ Array<CellCoords>

Gets the coordinates of all cells of your range.

getBordersSharedWith

Source code

cellRange.getBordersSharedWith(range) ⇒ Array<('top'|'right'|'bottom'|'left')>

Indicates which borders (top, right, bottom, left) are shared between your CellRangeinstance and another range that's within your range.

Param Type Description
range CellRange A range to compare with.

getBottomEndCorner

Source code

cellRange.getBottomEndCorner() ⇒ CellCoords

Gets the bottom right (in LTR) or bottom left (in RTL) corner coordinates of your range.

If the corner contains header coordinates (negative values), the corner coordinates are normalized to 0.

getBottomLeftCorner

Source code

cellRange.getBottomLeftCorner() ⇒ CellCoords

Gets the bottom left corner coordinates of your range, both in the LTR and RTL layout direction.

If the corner contains header coordinates (negative values), the corner coordinates are normalized to 0.

getBottomRightCorner

Source code

cellRange.getBottomRightCorner() ⇒ CellCoords

Gets the bottom right corner coordinates of your range, both in the LTR and RTL layout direction.

If the corner contains header coordinates (negative values), the corner coordinates are normalized to 0.

getBottomStartCorner

Source code

cellRange.getBottomStartCorner() ⇒ CellCoords

Gets the bottom left (in LTR) or bottom right (in RTL) corner coordinates of your range.

If the corner contains header coordinates (negative values), the corner coordinates are normalized to 0.

getCellsCount

Source code

cellRange.getCellsCount() ⇒ number

Returns the number of cells within your range (excluding column and row headers).

getDirection

Source code

cellRange.getDirection() ⇒ string

Gets the direction of the selection.

Returns: string - Returns one of the values: 'NW-SE', 'NE-SW', 'SE-NW', 'SW-NE'.

getHeight

Source code

cellRange.getHeight() ⇒ number

Returns the height of your range (as a number of rows, excluding row headers).

getHorizontalDirection

Source code

cellRange.getHorizontalDirection() ⇒ string

Gets the horizontal direction of the selection.

Returns: string - Returns one of the values: W-E (west->east), E-W (east->west).

getInner

Source code

cellRange.getInner() ⇒ Array<CellCoords>

Gets the coordinates of the inner cells of your range.

getOppositeCorner

Source code

cellRange.getOppositeCorner(coords) ⇒ CellCoords

Gets the coordinates of a range corner opposite to the provided coords.

For example: if the coords coordinates match the bottom-right corner of your range, the coordinates of the top-left corner of your range are returned.

Param Type Description
coords CellCoords Coordinates to check.

getOuterBottomEndCorner

Source code

cellRange.getOuterBottomEndCorner() ⇒ CellCoords

Gets the bottom right (in LTR) or bottom left (in RTL) corner coordinates of your range.

If the corner contains header coordinates (negative values), the top and start coordinates are pointed to that header.

getOuterBottomLeftCorner

Source code

cellRange.getOuterBottomLeftCorner() ⇒ CellCoords

Gets the bottom left corner coordinates of your range, both in the LTR and RTL layout direction.

If the corner contains header coordinates (negative values), the top and left coordinates are pointed to that header.

getOuterBottomRightCorner

Source code

cellRange.getOuterBottomRightCorner() ⇒ CellCoords

Gets the bottom right corner coordinates of your range, both in the LTR and RTL layout direction.

If the corner contains header coordinates (negative values), the top and left coordinates are pointed to that header.

getOuterBottomStartCorner

Source code

cellRange.getOuterBottomStartCorner() ⇒ CellCoords

Gets the bottom left (in LTR) or bottom right (in RTL) corner coordinates of your range.

If the corner contains header coordinates (negative values), the top and start coordinates are pointed to that header.

getOuterHeight

Source code

cellRange.getOuterHeight() ⇒ number

Returns the height of your range (as a number of rows, including row headers).

getOuterTopEndCorner

Source code

cellRange.getOuterTopEndCorner() ⇒ CellCoords

Gets the top right (in LTR) or top left (in RTL) corner coordinates of your range.

If the corner contains header coordinates (negative values), the top and start coordinates are pointed to that header.

getOuterTopLeftCorner

Source code

cellRange.getOuterTopLeftCorner() ⇒ CellCoords

Gets the top left corner coordinates of your range, both in the LTR and RTL layout direction.

If the corner contains header coordinates (negative values), the top and left coordinates are pointed to that header.

getOuterTopRightCorner

Source code

cellRange.getOuterTopRightCorner() ⇒ CellCoords

Gets the top right corner coordinates of your range, both in the LTR and RTL layout direction.

If the corner contains header coordinates (negative values), the top and left coordinates are pointed to that header.

getOuterTopStartCorner

Source code

cellRange.getOuterTopStartCorner() ⇒ CellCoords

Gets the top left (in LTR) or top right (in RTL) corner coordinates of your range.

If the corner contains header coordinates (negative values), the top and start coordinates are pointed to that header.

getOuterWidth

Source code

cellRange.getOuterWidth() ⇒ number

Returns the width of your range (as a number of columns, including column headers).

getTopEndCorner

Source code

cellRange.getTopEndCorner() ⇒ CellCoords

Gets the top right (in LTR) or top left (in RTL) corner coordinates of your range.

If the corner contains header coordinates (negative values), the corner coordinates are normalized to 0.

getTopLeftCorner

Source code

cellRange.getTopLeftCorner() ⇒ CellCoords

Gets the top-left corner coordinates of your range, both in the LTR and RTL layout direction.

If the corner contains header coordinates (negative values), the corner coordinates are normalized to 0.

getTopRightCorner

Source code

cellRange.getTopRightCorner() ⇒ CellCoords

Gets the top right corner coordinates of your range, both in the LTR and RTL layout direction.

If the corner contains header coordinates (negative values), the corner coordinates are normalized to 0.

getTopStartCorner

Source code

cellRange.getTopStartCorner() ⇒ CellCoords

Gets the top-left (in LTR) or top-right (in RTL) corner coordinates of your range.

If the corner contains header coordinates (negative values), the corner coordinates are normalized to 0.

getVerticalDirection

Source code

cellRange.getVerticalDirection() ⇒ string

Gets the vertical direction of the selection.

Returns: string - Returns one of the values: N-S (north->south), S-N (south->north).

getWidth

Source code

cellRange.getWidth() ⇒ number

Returns the width of your range (as a number of columns, excluding column headers).

includes

Source code

cellRange.includes(cellCoords) ⇒ boolean

Checks if another set of coordinates (cellCoords) is within the from and to coordinates of your range.

Param Type Description
cellCoords CellCoords Coordinates to check.

includesRange

Source code

cellRange.includesRange(cellRange) ⇒ boolean

Checks if another range (cellRange) is within your range.

Param Type Description
cellRange CellRange A range to check.

isCorner

Source code

cellRange.isCorner(coords) ⇒ boolean

Checks if a set of coordinates (coords) matches one of the 4 corners of your range.

Param Type Description
coords CellCoords Coordinates to check.

isEqual

Source code

cellRange.isEqual(cellRange) ⇒ boolean

Checks if another range (cellRange) is equal to your range.

Param Type Description
cellRange CellRange A range to check.

isHeader

Source code

cellRange.isHeader() ⇒ boolean

Checks if your range covers only headers range (negative coordinates, without any cells).

isNorthWestOf

Source code

cellRange.isNorthWestOf(cellCoords) ⇒ boolean

Checks if coordinates point is north-west of your range.

Param Type Description
cellCoords CellRange Coordinates to check.

isOverlappingHorizontally

Source code

cellRange.isOverlappingHorizontally(cellRange) ⇒ boolean

Checks if another range (cellRange) overlaps your range horizontally.

For example: returns true if the last column of your range is 5 and the first column of the cellRange range is 3.

Param Type Description
cellRange CellRange A range to check.

isOverlappingVertically

Source code

cellRange.isOverlappingVertically(cellRange) ⇒ boolean

Checks if another range (cellRange) overlaps your range vertically.

For example: returns true if the last row of your range is 5 and the first row of the cellRange range is 3.

Param Type Description
cellRange CellRange A range to check.

isSingle

Source code

cellRange.isSingle() ⇒ boolean

Checks if your range is just a single cell or header.

isSingleCell

Source code

cellRange.isSingleCell() ⇒ boolean

Checks if your range is just a single cell.

isSingleHeader

Source code

cellRange.isSingleHeader() ⇒ boolean

Checks if your range is just a single header.

isSouthEastOf

Source code

cellRange.isSouthEastOf(cellCoords) ⇒ boolean

Checks if coordinates point is south-east of your range.

Param Type Description
cellCoords CellCoords Coordinates to check.

isValid

Source code

cellRange.isValid(tableParams) ⇒ boolean

Checks if the coordinates in your CellRange instance are valid in the context of given table parameters.

See the isValid() method of the CellCoords class.

Param Type Description
tableParams object An object with a defined table size.
tableParams.countRows number The total number of rows.
tableParams.countCols number The total number of columns.
tableParams.countRowHeaders number A number of row headers.
tableParams.countColHeaders number A number of column headers.

overlaps

Source code

cellRange.overlaps(cellRange) ⇒ boolean

Checks if another range (cellRange) overlaps your range.

Range A overlaps range B if the intersection of A and B (or B and A) is not empty.

Param Type Description
cellRange CellRange A range to check.

setDirection

Source code

cellRange.setDirection(direction)

Sets the direction of the selection.

Param Type Description
direction string One of the values: 'NW-SE', 'NE-SW', 'SE-NW', 'SW-NE'.

setFrom

Source code

cellRange.setFrom(coords) ⇒ CellRange

Sets the coords coordinates as the start of your range.

Param Type Description
coords CellCoords Coordinates to use.

setHighlight

Source code

cellRange.setHighlight(coords) ⇒ CellRange

Highlights cell selection at the coords coordinates.

Param Type Description
coords CellCoords Coordinates to use.

setTo

Source code

cellRange.setTo(coords) ⇒ CellRange

Sets the coords coordinates as the end of your range.

Param Type Description
coords CellCoords Coordinates to use.

toObject

Source code

cellRange.toObject() ⇒ Object

Converts your CellRange instance into an object literal with the following properties:

  • from
    • row
    • col
  • to
    • row
    • col

Returns: Object - An object literal with from and to properties.