CellRange
Plugin: CellRange
- Description
- Methods
- clone
- containsHeaders
- expand
- expandByRange
- flipDirectionHorizontally
- flipDirectionVertically
- forAll
- getAll
- getBordersSharedWith
- getBottomEndCorner
- getBottomLeftCorner
- getBottomRightCorner
- getBottomStartCorner
- getCellsCount
- getDirection
- getHeight
- getHorizontalDirection
- getInner
- getOppositeCorner
- getOuterBottomEndCorner
- getOuterBottomLeftCorner
- getOuterBottomRightCorner
- getOuterBottomStartCorner
- getOuterHeight
- getOuterTopEndCorner
- getOuterTopLeftCorner
- getOuterTopRightCorner
- getOuterTopStartCorner
- getOuterWidth
- getTopEndCorner
- getTopLeftCorner
- getTopRightCorner
- getTopStartCorner
- getVerticalDirection
- getWidth
- includes
- includesRange
- isCorner
- isEqual
- isHeader
- isNorthWestOf
- isOverlappingHorizontally
- isOverlappingVertically
- isSingle
- isSingleCell
- isSingleHeader
- isSouthEastOf
- isValid
- normalize
- overlaps
- setDirection
- setFrom
- setHighlight
- setTo
- toObject
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:
Methods
clone
cellRange.clone() ⇒ CellRange
Clones your CellRange instance.
cellRange.containsHeaders() ⇒ boolean
Checks if your range overlaps headers range (negative coordinates).
expand
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
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
cellRange.flipDirectionHorizontally()
Flips the direction of your range horizontally (e.g., NW-SE changes to NE-SW).
flipDirectionVertically
cellRange.flipDirectionVertically()
Flips the direction of your range vertically (e.g., NW-SE changes to SW-NE).
forAll
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
cellRange.getAll() ⇒ Array<CellCoords>
Gets the coordinates of all cells of your range.
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
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
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
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
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
cellRange.getCellsCount() ⇒ number
Returns the number of cells within your range (excluding column and row headers).
getDirection
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
cellRange.getHeight() ⇒ number
Returns the height of your range (as a number of rows, excluding row headers).
getHorizontalDirection
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
cellRange.getInner() ⇒ Array<CellCoords>
Gets the coordinates of the inner cells of your range.
getOppositeCorner
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
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
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
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
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
cellRange.getOuterHeight() ⇒ number
Returns the height of your range (as a number of rows, including row headers).
getOuterTopEndCorner
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
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
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
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
cellRange.getOuterWidth() ⇒ number
Returns the width of your range (as a number of columns, including column headers).
getTopEndCorner
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
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
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
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
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
cellRange.getWidth() ⇒ number
Returns the width of your range (as a number of columns, excluding column headers).
includes
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
cellRange.includesRange(cellRange) ⇒ boolean
Checks if another range (cellRange) is within your range.
| Param | Type | Description |
|---|---|---|
| cellRange | CellRange | A range to check. |
isCorner
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
cellRange.isEqual(cellRange) ⇒ boolean
Checks if another range (cellRange) is equal to your range.
| Param | Type | Description |
|---|---|---|
| cellRange | CellRange | A range to check. |
cellRange.isHeader() ⇒ boolean
Checks if your range covers only headers range (negative coordinates, without any cells).
isNorthWestOf
cellRange.isNorthWestOf(cellCoords) ⇒ boolean
Checks if coordinates point is north-west of your range.
| Param | Type | Description |
|---|---|---|
| cellCoords | CellRange | Coordinates to check. |
isOverlappingHorizontally
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
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
cellRange.isSingle() ⇒ boolean
Checks if your range is just a single cell or header.
isSingleCell
cellRange.isSingleCell() ⇒ boolean
Checks if your range is just a single cell.
cellRange.isSingleHeader() ⇒ boolean
Checks if your range is just a single header.
isSouthEastOf
cellRange.isSouthEastOf(cellCoords) ⇒ boolean
Checks if coordinates point is south-east of your range.
| Param | Type | Description |
|---|---|---|
| cellCoords | CellCoords | Coordinates to check. |
isValid
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. |
normalize
cellRange.normalize() ⇒ CellRange
Normalizes the coordinates in your CellRange instance to the nearest valid position.
Coordinates that point to headers (negative values) are normalized to 0.
overlaps
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
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
cellRange.setFrom(coords) ⇒ CellRange
Sets the coords coordinates as the start of your range.
| Param | Type | Description |
|---|---|---|
| coords | CellCoords | Coordinates to use. |
setHighlight
cellRange.setHighlight(coords) ⇒ CellRange
Highlights cell selection at the coords coordinates.
| Param | Type | Description |
|---|---|---|
| coords | CellCoords | Coordinates to use. |
setTo
cellRange.setTo(coords) ⇒ CellRange
Sets the coords coordinates as the end of your range.
| Param | Type | Description |
|---|---|---|
| coords | CellCoords | Coordinates to use. |
toObject
cellRange.toObject() ⇒ Object
Converts your CellRange instance into an object literal with the following properties:
fromrowcol
torowcol
Returns: Object - An object literal with from and to properties.