type
Grid
@Js
const mixin Grid
Two dimensional tabular data structure composed of Cols and Rows. Grids may be created by factory methods on Etc
or using GridBuilder
. See docHaystack.
methods
addCol |
Return a new grid with an additional column. |
---|---|
addColMeta |
Return a new grid with additional column meta-data. |
addCols |
Return a new grid by adding the given grid as a new set of columns to this grid. |
addMeta |
Return a new grid with additional grid level meta-data. |
all |
Return true if the function returns true for all of the rows in the grid. |
any |
Return true if the function returns true for any of the rows in the grid. |
col |
Get a column by its name. |
colDisNames | |
colNames | |
colToList |
Get a column as a list of the cell values ordered by row. |
cols |
Columns |
colsToLocale |
Return a new Grid wich each col name mapped to its localized tag name if the col does not already have a display string. |
commit |
Return a new Grid which is the result of applying the given diffs to this grid. |
each |
Iterate the rows |
eachWhile |
Iterate every row until the function returns non-null. |
filter |
Return a new grid which finds matching rows based on the given filter. |
find |
Find one matching row or return null if no matches. |
findAll |
Return a new grid which finds matching the rows in this grid. |
findIndex |
Find one matching row index or return null if no matches. |
first |
Get the first row or return null if grid is empty. |
flatMap |
Return a new grid which maps each of the rows to zero or more new Dicts. |
get |
Get a row by its index number. |
getRange |
Return a new grid which is a slice of the rows in this grid. |
getSafe |
Get a row by its index number or if index is out of bounds then return null. |
has |
Return if this grid contains the given column name. |
isEmpty |
Convenience for |
isErr |
Return if this is an error grid - meta has "err" tag. |
isHisGrid |
Return if this grid conforms to the history grid shape |
join |
Join two grids by column name. |
keepCols |
Return a new grid with all the columns removed except the given columns. |
last |
Get the last row or return null if grid is empty. |
map |
Return a new grid which maps the rows to new Dict. |
mapToList |
Map each row to a list of values. |
meta |
Meta-data for entire grid |
missing |
Return if this grid does not contains the given column name. |
removeCol |
Return a new grid with the given column removed. |
removeCols |
Return a new grid with all the given columns removed. |
renameCol |
Return a new grid with the given column renamed. |
renameCols |
Return a new grid with multiple columns renamed. |
reorderCols |
Return a new grid with the columns reordered. |
replace |
Replace every cell with the given |
setColMeta |
Return new grid with column meta-data replaced by given meta. |
setMeta |
Return a new grid with grid level meta-data replaced by given meta. |
size |
Get the number of rows in the grid. |
sort |
Return a new Grid which is a copy of this grid with the rows sorted by the given comparator function. |
sortCol |
Convenience for |
sortColr |
Sort the given column in reverse. |
sortDis |
Sort using |
sortr |
Return a new Grid which is a copy of this grid with the rows reverse sorted by the given comparator function. |
unique |
Return a new grid with only rows that define a unique key by the given key columns. |
Slot Details
addCol
addColMeta
Grid addColMeta(Obj col, Obj? meta)
Return a new grid with additional column meta-data. The new tags are merged according to Etc.dictMerge
. The col
parameter may be either a Col
or column name. The meta may be any value accepted by Etc.makeDict
. If column is not found then return this. Also see setColMeta
.
addCols
Return a new grid by adding the given grid as a new set of columns to this grid. If the given grid contains duplicate column names, then they are given auto-generated unique names. If the given grid contains fewer rows then this grid, then the missing cells are filled with null.
addMeta
Return a new grid with additional grid level meta-data. The new tags are merged according to Etc.dictMerge
. The meta may be any value accepted by Etc.makeDict
Also see setMeta
.
all
any
col
colDisNames
colNames
colToList
cols
abstract Col[] cols()
Columns
colsToLocale
Grid colsToLocale()
Return a new Grid wich each col name mapped to its localized tag name if the col does not already have a display string. See Etc.tagToLocale
and Localization
.
commit
each
eachWhile
filter
Grid filter(Filter filter, HaystackContext? cx := null)
Return a new grid which finds matching rows based on the given filter. Also see findAll
.
find
findAll
findIndex
first
abstract Row? first()
Get the first row or return null if grid is empty.
flatMap
get
getRange
getSafe
has
isEmpty
isErr
Bool isErr()
Return if this is an error grid - meta has "err" tag.
isHisGrid
Bool isHisGrid()
Return if this grid conforms to the history grid shape:
- has at least two columns
- first column is named "ts"
- has meta hisStart and hisEnd DateTime values
This method does not check timezones or the ts cells.
join
Grid join(Grid that, Obj joinCol)
Join two grids by column name. The joinCol
parameter may be a Col
or col name. Current implementation requires:
- grids cannot have conflicting col names (other than join col)
- each row in both grids must have a unique value for join col
- grid level meta is merged
- join column meta is merged
keepCols
last
virtual Row? last()
Get the last row or return null if grid is empty. Throw UnsupportedErr is the grid doesn't support indexed based row access.
map
mapToList
meta
abstract Dict meta()
Meta-data for entire grid
missing
removeCol
removeCols
renameCol
renameCols
reorderCols
replace
setColMeta
Grid setColMeta(Obj col, Obj? meta)
Return new grid with column meta-data replaced by given meta. The col
parameter may be either a Col
or column name. The meta may be any value accepted by Etc.makeDict
If column is not found then return this. Also see addColMeta
.
setMeta
Return a new grid with grid level meta-data replaced by given meta. The meta may be any value accepted by Etc.makeDict
. Also see addMeta
.
size
abstract Int size()
Get the number of rows in the grid. Throw UnsupportedErr if the grid doesn't support a size.
sort
sortCol
sortColr
sortDis
Grid sortDis()
Sort using Etc.compareDis
and Dict.dis
.