TableModel represents a data model for two-dimensional data. It's used for all things table (table component, table toolbar, pagination, etc)

TableModel manages its internal data integrity very well if you use the provided helper functions for modifying rows and columns and assigning header and data in that order.

### Hierarchy

- AITableModel

### Implements

- PaginationModel

## Index

### Constructors

- constructor

### Properties

- _data
- _totalDataLength
- currentPage
- dataChange
- header
- isEnd
- isLoading
- pageLength
- rowsClass
- rowsContext
- rowsExpanded
- rowsExpandedChange
- rowsSelected
- rowsSelectedChange
- selectAllChange
- tableModelCount
- COUNT

### Accessors

- totalDataLength

### Methods

- actualIndexToProjectedIndices
- addColumn
- addRow
- column
- deleteColumn
- deleteRow
- expandRow
- expandedRowIndices
- expandedRowsCount
- getClosestHeader
- getHeaderId
- getId
- getRowContext
- hasExpandableRows
- isRowDisabled
- isRowExpandable
- isRowExpanded
- isRowFiltered
- isRowSelected
- moveColumn
- moveMultipleToIndex
- moveNested
- nestedToTabular
- popRowStateFromModelData
- projectedIndexToActualIndex
- projectedIndicesToActualIndices
- projectedRowLength
- projectedRowLengthSimple
- pushRowStateToModelData
- realColumnIndex
- realIndex
- realRowIndex
- row
- rowMetaInfo
- rows
- selectAll
- selectRow
- selectedRowIndices
- selectedRowsCount
- setData
- setHeader
- setItem
- setItemData
- setRowContext
- sort
- tabularToNested

## Constructors

### constructor

- new AITableModel(): AITableModel

- - Defined in packages/angular/src/table/table-model.class.ts:145

  #### Returns AITableModel

## Properties

### Protected _data

_data: TableItem[][] = ...

- Defined in packages/angular/src/table/table-model.class.ts:114

Used in `data`

### Protected _totalDataLength

_totalDataLength: number

- Defined in packages/angular/src/table/table-model.class.ts:78

Absolute total number of rows of the table.

### currentPage

currentPage: number = 1

- Defined in packages/angular/src/table/table-model.class.ts:58

Tracks the current page.

### dataChange

dataChange: Subject<unknown> = ...

- Defined in packages/angular/src/table/table-model.class.ts:37

### Protected header

header: AITableHeaderItem[][] = ...

- Defined in packages/angular/src/table/table-model.class.ts:119

Contains information about the header cells of the table.

### isEnd

isEnd: boolean = false

- Defined in packages/angular/src/table/table-model.class.ts:68

Set to true when there is no more data to load in the table

### isLoading

isLoading: boolean = false

- Defined in packages/angular/src/table/table-model.class.ts:73

Set to true when lazy loading to show loading indicator

### pageLength

pageLength: number = 10

- Defined in packages/angular/src/table/table-model.class.ts:63

Length of page.

### rowsClass

rowsClass: string[] = ...

- Defined in packages/angular/src/table/table-model.class.ts:53

Contains class name(s) of the row.

It affects styling of the row to reflect the appended class name(s).

It's empty or undefined by default

### Protected rowsContext

rowsContext: string[] = ...

- Defined in packages/angular/src/table/table-model.class.ts:145

Contains information about the context of the row.

It affects styling of the row to reflect the context.

string can be one of `"success" | "warning" | "info" | "error" | ""` and it's empty or undefined by default

### Protected rowsExpanded

rowsExpanded: boolean[] = ...

- Defined in packages/angular/src/table/table-model.class.ts:135

Contains information about expanded state of rows in the table.

### rowsExpandedChange

rowsExpandedChange: Subject<number> = ...

- Defined in packages/angular/src/table/table-model.class.ts:39

### Protected rowsSelected

rowsSelected: boolean[] = ...

- Defined in packages/angular/src/table/table-model.class.ts:130

Contains information about selection state of rows in the table.

### rowsSelectedChange

rowsSelectedChange: Subject<number> = ...

- Defined in packages/angular/src/table/table-model.class.ts:38

### selectAllChange

selectAllChange: Subject<boolean> = ...

- Defined in packages/angular/src/table/table-model.class.ts:44

Gets emitted when `selectAll` is called. Emits false if all rows are deselected and true if all rows are selected.

### Protected tableModelCount

tableModelCount: number = 0

- Defined in packages/angular/src/table/table-model.class.ts:125

The number of models instantiated, this is to make sure each table has a different model count for unique id generation.

### Protected Static COUNT

COUNT: number = 0

- Defined in packages/angular/src/table/table-model.class.ts:35

The number of models instantiated, used for (among other things) unique id generation

## Accessors

### totalDataLength

- get totalDataLength(): number
- set totalDataLength(length: number): void

- - Defined in packages/angular/src/table/table-model.class.ts:97

  Total length of data that table has access to, or the amount manually set

  Example: if you have multiple pages of data that table will display but you're loading one at a time.

  Set to `null` to reset to default behavior.

  #### Returns number

- - Defined in packages/angular/src/table/table-model.class.ts:89

  Manually set data length in case the data in the table doesn't correctly reflect all the data that table is to display.

  Example: if you have multiple pages of data that table will display but you're loading one at a time.

  Set to `null` to reset to default behavior.

  #### Parameters

  - ##### length: number

  #### Returns void

## Methods

### Protected actualIndexToProjectedIndices

- actualIndexToProjectedIndices(actualIndex: number, list: TableItem[] | AITableHeaderItem[]): number[]

- - Defined in packages/angular/src/table/table-model.class.ts:975

  Convert an actual index to a projected indices array

  #### Parameters

  - ##### actualIndex: number

    index of a column as-is

  - ##### list: TableItem[] | AITableHeaderItem[]

    a row of the header or the body

  #### Returns number[]

### addColumn

- addColumn(column?: TableItem[], index?: number): void

- - Defined in packages/angular/src/table/table-model.class.ts:554

  Adds a column to the `index`th column or appends to table if index not provided.

  If column is shorter than other columns or not provided, it will be padded with empty `TableItem` elements.

  If column is longer than other columns, others will be extended to match so no data is lost.

  If called on an empty table with no parameters, it creates a 1x1 table.

  Negative index starts from the end. -1 being the last element.

  #### Parameters

  - ##### Optional column: TableItem[]

  - ##### Optional index: number

  #### Returns void

### addRow

- addRow(row?: TableItem[], index?: number): void

- - Defined in packages/angular/src/table/table-model.class.ts:392

  Adds a row to the `index`th row or appends to table if index not provided.

  If row is shorter than other rows or not provided, it will be padded with empty `TableItem` elements.

  If row is longer than other rows, others will be extended to match so no data is lost.

  If called on an empty table with no parameters, it creates a 1x1 table.

  Negative index starts from the end. -1 being the last element.

  #### Parameters

  - ##### Optional row: TableItem[]

  - ##### Optional index: number

  #### Returns void

### column

- column(index: number): TableItem[]

- - Defined in packages/angular/src/table/table-model.class.ts:526

  Returns `index`th column of the table.

  Negative index starts from the end. -1 being the last element.

  #### Parameters

  - ##### index: number

  #### Returns TableItem[]

### deleteColumn

- deleteColumn(index: number): void

- - Defined in packages/angular/src/table/table-model.class.ts:622

  Deletes `index`th column.

  Negative index starts from the end. -1 being the last element.

  #### Parameters

  - ##### index: number

  #### Returns void

### deleteRow

- deleteRow(index: number): void

- - Defined in packages/angular/src/table/table-model.class.ts:478

  Deletes `index`th row.

  Negative index starts from the end. -1 being the last element.

  #### Parameters

  - ##### index: number

  #### Returns void

### expandRow

- expandRow(index: number, value?: boolean): void

- - Defined in packages/angular/src/table/table-model.class.ts:874

  Expands/Collapses `index`th row based on value

  #### Parameters

  - ##### index: number

    index of the row to expand or collapse

  - ##### value: boolean = true

    expanded state of the row. `true` is expanded and `false` is collapsed

  #### Returns void

### expandedRowIndices

- expandedRowIndices(): number[]

- - Defined in packages/angular/src/table/table-model.class.ts:332

  #### Returns number[]

  a list of indices of expanded rows

### expandedRowsCount

- expandedRowsCount(): number

- - Defined in packages/angular/src/table/table-model.class.ts:345

  Returns how many rows is currently expanded

  #### Returns number

### getClosestHeader

- getClosestHeader(column: any): AITableHeaderItem

- - Defined in packages/angular/src/table/table-model.class.ts:278

  Finds closest header by trying the lowest cell in header and then work its way to the left

  #### Parameters

  - ##### column: any

  #### Returns AITableHeaderItem

### getHeaderId

- getHeaderId(column: HeaderType, colSpan?: number): string

- - Defined in packages/angular/src/table/table-model.class.ts:256

  Returns the id of the header. Used to link the cells with headers (or headers with headers)

  #### Parameters

  - ##### column: HeaderType

    the column to start getting headers for

  - ##### colSpan: number = 1

    the number of columns to get headers for (defaults to 1)

  #### Returns string

### getId

- getId(column: HeaderType, row?: number): string

- - Defined in packages/angular/src/table/table-model.class.ts:246

  Returns an id for the given column

  #### Parameters

  - ##### column: HeaderType

    the column to generate an id for

  - ##### row: number = 0

    the row of the header to generate an id for

  #### Returns string

### getRowContext

- getRowContext(index: number): string

- - Defined in packages/angular/src/table/table-model.class.ts:511

  #### Parameters

  - ##### index: number

  #### Returns string

### hasExpandableRows

- hasExpandableRows(): boolean

- - Defined in packages/angular/src/table/table-model.class.ts:499

  #### Returns boolean

### isRowDisabled

- isRowDisabled(index: number): boolean

- - Defined in packages/angular/src/table/table-model.class.ts:863

  Checks if row is disabled or not.

  #### Parameters

  - ##### index: number

  #### Returns boolean

### isRowExpandable

- isRowExpandable(index: number): boolean

- - Defined in packages/angular/src/table/table-model.class.ts:503

  #### Parameters

  - ##### index: number

  #### Returns boolean

### isRowExpanded

- isRowExpanded(index: number): boolean

- - Defined in packages/angular/src/table/table-model.class.ts:507

  #### Parameters

  - ##### index: number

  #### Returns boolean

### isRowFiltered

- isRowFiltered(index: number): boolean

- - Defined in packages/angular/src/table/table-model.class.ts:819

  Checks if row is filtered out.

  #### Parameters

  - ##### index: number

  #### Returns boolean

  true if any of the filters in header filters out the `index`th row

### isRowSelected

- isRowSelected(index: number): boolean

- - Defined in packages/angular/src/table/table-model.class.ts:856

  #### Parameters

  - ##### index: number

  #### Returns boolean

### moveColumn

- moveColumn(indexFrom: number, indexTo: number, rowIndex?: number): void

- - Defined in packages/angular/src/table/table-model.class.ts:736

  Move the column at `indexFrom` to `indexTo` of the `rowIndex` row

  Note: only works with one row headers at the moment

  If headers have merged cells, they should only be merged in a way that a higher row contains all the lower row columns and not vice versa

  Multiline header example (good):

  | h1 | h2 |||| | h11 | h12 || h13 || | h21 | h22 | h23 | h24 | h25 | |-----|-----|-----|-----|-----| | a | b | c | d | e | | f | g | h | i | j |

  Multiline header example (not good):

  | h1 | h2 |||| | h21 | h22 | h23 | h24 | h25 | | h11 | h12 || h13 || |-----|-----|-----|-----|-----| | a | b | c | d | e | | f | g | h | i | j |

  ## Usage example:

  ### Moving h2 in place of h1

  `model.moveColumn(1, 0)`

  Before

  | h1 | h2 |||| | h11 | h12 || h13 || | h21 | h22 | h23 | h24 | h25 | |-----|-----|-----|-----|-----| | a | b | c | d | e | | f | g | h | i | j |

  After

  | h2 | h1 |||| | h12 || h13 | h11 || | h22 | h23 | h24 | h25 | h21 | |-----|-----|-----|-----|-----| | b | c | d | e | a | | g | h | i | j | f |

  ### Moving h13 in place of h12

  `model.moveColumn(2, 1, 1)`

  Before

  | h1 | h2 |||| | h11 | h12 || h13 || | h21 | h22 | h23 | h24 | h25 | |-----|-----|-----|-----|-----| | a | b | c | d | e | | f | g | h | i | j |

  After

  | h1 | h2 |||| | h11 | h13 || h12 || | h21 | h24 | h25 | h22 | h23 | |-----|-----|-----|-----|-----| | a | d | e | b | c | | f | i | j | g | h |

  ### Moving h24 in place of h25

  `model.moveColumn(3, 4, 2)`

  Note: while you could move h24 to h22, you shouldn't because it doesn't belong under the same subheader.

  Before

  | h1 | h2 |||| | h11 | h12 || h13 || | h21 | h22 | h23 | h24 | h25 | |-----|-----|-----|-----|-----| | a | b | c | d | e | | f | g | h | i | j |

  After

  | h1 | h2 |||| | h11 | h12 || h13 || | h21 | h22 | h23 | h25 | h24 | |-----|-----|-----|-----|-----| | a | b | c | e | d | | f | g | h | j | i |

  #### Parameters

  - ##### indexFrom: number

  - ##### indexTo: number

  - ##### rowIndex: number = 0

  #### Returns void

### Protected moveMultipleToIndex

- moveMultipleToIndex(indices: number[], index: any, list: TableItem[] | AITableHeaderItem[]): void

- - Defined in packages/angular/src/table/table-model.class.ts:1002

  #### Parameters

  - ##### indices: number[]

  - ##### index: any

  - ##### list: TableItem[] | AITableHeaderItem[]

  #### Returns void

### Protected moveNested

- moveNested(nested: any, indexFrom: number, indexTo: number, rowIndex?: number, startingChildIndex?: number): void

- - Defined in packages/angular/src/table/table-model.class.ts:1118

  Move `nested` element at `rowIndex` with index `indexFrom` to `indexTo`.

  #### Parameters

  - ##### nested: any

  - ##### indexFrom: number

  - ##### indexTo: number

  - ##### rowIndex: number = 0

  - ##### startingChildIndex: number = 0

  #### Returns void

### Protected nestedToTabular

- nestedToTabular(nested: any, header?: AITableHeaderItem[][], data?: TableItem[][], rowIndex?: number): { data: TableItem[][]; header: AITableHeaderItem[][] }

- - Defined in packages/angular/src/table/table-model.class.ts:1080

  #### Parameters

  - ##### nested: any

  - ##### header: AITableHeaderItem[][] = ...

  - ##### data: TableItem[][] = ...

  - ##### rowIndex: number = 0

  #### Returns { data: TableItem[][]; header: AITableHeaderItem[][] }

  - ##### data: TableItem[][]

  - ##### header: AITableHeaderItem[][]

### popRowStateFromModelData

- popRowStateFromModelData(): void

- - Defined in packages/angular/src/table/table-model.class.ts:804

  Restores `rowsSelected` from data pushed by `pushRowSelectionToModelData()`

  Call after sorting data (if you previously pushed to maintain selection order) to make everything right with the world again.

  #### Returns void

### Protected projectedIndexToActualIndex

- projectedIndexToActualIndex(projectedIndex: number, list: TableItem[] | AITableHeaderItem[]): number

- - Defined in packages/angular/src/table/table-model.class.ts:955

  Convert a projected index to actual index, where actual index is the index in the list that's passed in

  #### Parameters

  - ##### projectedIndex: number

    index of a column if none of the cells were merged

  - ##### list: TableItem[] | AITableHeaderItem[]

    a row of the header or the body

  #### Returns number

### Protected projectedIndicesToActualIndices

- projectedIndicesToActualIndices(projectedIndices: number[], list: TableItem[] | AITableHeaderItem[]): number[]

- - Defined in packages/angular/src/table/table-model.class.ts:989

  #### Parameters

  - ##### projectedIndices: number[]

  - ##### list: TableItem[] | AITableHeaderItem[]

  #### Returns number[]

### Protected projectedRowLength

- projectedRowLength(itemArray: any[], rowIndex?: number, matrix?: any[][]): any

- - Defined in packages/angular/src/table/table-model.class.ts:926

  #### Parameters

  - ##### itemArray: any[]

    TableItem[] | AITableHeaderItem[]

  - ##### Optional rowIndex: number

  - ##### Optional matrix: any[][]

  #### Returns any

  the number of columns as if now cells were merged

### Protected projectedRowLengthSimple

- projectedRowLengthSimple(itemArray: any[]): any

- - Defined in packages/angular/src/table/table-model.class.ts:918

  #### Parameters

  - ##### itemArray: any[]

  #### Returns any

### pushRowStateToModelData

- pushRowStateToModelData(): void

- - Defined in packages/angular/src/table/table-model.class.ts:778

  Appends `rowsSelected` and `rowsExpanded` info to model data.

  When sorting rows, do this first so information about row selection gets sorted with the other row info.

  Call `popRowSelectionFromModelData()` after sorting to make everything right with the world again.

  #### Returns void

### Protected realColumnIndex

- realColumnIndex(index: number): number

- - Defined in packages/angular/src/table/table-model.class.ts:897

  Gets the true index of a column based on it's relative position. Like in Python, positive numbers start from the top and negative numbers start from the bottom.

  #### Parameters

  - ##### index: number

  #### Returns number

### Protected realIndex

- realIndex(index: number, length: number): number

- - Defined in packages/angular/src/table/table-model.class.ts:908

  Generic function to calculate the real index of something. Used by `realRowIndex()` and `realColumnIndex()`

  #### Parameters

  - ##### index: number

  - ##### length: number

  #### Returns number

### Protected realRowIndex

- realRowIndex(index: number): number

- - Defined in packages/angular/src/table/table-model.class.ts:886

  Gets the true index of a row based on it's relative position. Like in Python, positive numbers start from the top and negative numbers start from the bottom.

  #### Parameters

  - ##### index: number

  #### Returns number

### row

- row(index: number): TableItem[]

- - Defined in packages/angular/src/table/table-model.class.ts:364

  Returns `index`th row of the table.

  Negative index starts from the end. -1 being the last element.

  #### Parameters

  - ##### index: number

  #### Returns TableItem[]

### rowMetaInfo

- rowMetaInfo(index: number): { context: string; expandable: boolean; expanded: boolean; rowClass: string; selected: boolean }

- - Defined in packages/angular/src/table/table-model.class.ts:489

  #### Parameters

  - ##### index: number

  #### Returns { context: string; expandable: boolean; expanded: boolean; rowClass: string; selected: boolean }

  - ##### context: string

  - ##### expandable: boolean

  - ##### expanded: boolean

  - ##### rowClass: string

  - ##### selected: boolean

### rows

- rows(): TableItem[][]

- - Defined in packages/angular/src/table/table-model.class.ts:373

  Returns all the rows.

  Use `row()` instead.

  #### Returns TableItem[][]

### selectAll

- selectAll(value?: boolean): void

- - Defined in packages/angular/src/table/table-model.class.ts:847

  Selects or deselects all rows in the model

  #### Parameters

  - ##### value: boolean = true

    state to set all rows to. Defaults to `true`

  #### Returns void

### selectRow

- selectRow(index: number, value?: boolean, emitChange?: boolean): void

- - Defined in packages/angular/src/table/table-model.class.ts:832

  Select/deselect `index`th row based on value

  #### Parameters

  - ##### index: number

    index of the row to select

  - ##### value: boolean = true

    state to set the row to. Defaults to `true`

  - ##### emitChange: boolean = true

  #### Returns void

### selectedRowIndices

- selectedRowIndices(): number[]

- - Defined in packages/angular/src/table/table-model.class.ts:304

  #### Returns number[]

  a list of indices of selected rows

### selectedRowsCount

- selectedRowsCount(): number

- - Defined in packages/angular/src/table/table-model.class.ts:317

  Returns how many rows is currently selected

  #### Returns number

### setData

- setData(newData: TableItem[][]): void

- - Defined in packages/angular/src/table/table-model.class.ts:156

  Sets data of the table.

  Make sure all rows are the same length to keep the column count accurate.

  #### Parameters

  - ##### newData: TableItem[][]

  #### Returns void

### setHeader

- setHeader(newHeader: TableHeaderItem[] | TableHeaderItem[][] | AITableHeaderItem[] | AITableHeaderItem[][]): void

- - Defined in packages/angular/src/table/table-model.class.ts:207

  Sets data of the table.

  Make sure all rows are the same length to keep the column count accurate.

  #### Parameters

  - ##### newHeader: TableHeaderItem[] | TableHeaderItem[][] | AITableHeaderItem[] | AITableHeaderItem[][]

  #### Returns void

### setItem

- setItem(rowIndex: number, columnIndex: number, item: TableItem): void

- - Defined in packages/angular/src/table/table-model.class.ts:230

  #### Parameters

  - ##### rowIndex: number

  - ##### columnIndex: number

  - ##### item: TableItem

  #### Returns void

### setItemData

- setItemData(rowIndex: number, columnIndex: number, data: any): void

- - Defined in packages/angular/src/table/table-model.class.ts:235

  #### Parameters

  - ##### rowIndex: number

  - ##### columnIndex: number

  - ##### data: any

  #### Returns void

### setRowContext

- setRowContext(index: number, context: string): string

- - Defined in packages/angular/src/table/table-model.class.ts:515

  #### Parameters

  - ##### index: number

  - ##### context: string

  #### Returns string

### sort

- sort(index: number): void

- - Defined in packages/angular/src/table/table-model.class.ts:752

  Sorts the data currently present in the model based on `compare()`

  Direction is set by `ascending` and `descending` properties of `AITableHeaderItem` in `index`th column.

  #### Parameters

  - ##### index: number

    The column based on which it's sorting

  #### Returns void

### Protected tabularToNested

- tabularToNested(headerRow?: AITableHeaderItem[], availableHeaderItems?: AITableHeaderItem[][], leafIndexRef?: { current: number }, rowIndex?: number): any

- - Defined in packages/angular/src/table/table-model.class.ts:1019

  #### Parameters

  - ##### headerRow: AITableHeaderItem[] = ...

  - ##### availableHeaderItems: AITableHeaderItem[][] = ...

  - ##### leafIndexRef: { current: number } = ...

    - ##### current: number

  - ##### rowIndex: number = 0

  #### Returns any

Generated using TypeDoc