# GC.Spread.Sheets.Tables.TableManager

## Content

# Class: TableManager

[Sheets](../modules/GC.Spread.Sheets).[Tables](../modules/GC.Spread.Sheets.Tables).TableManager

## Table of contents

### Constructors

- [constructor](GC.Spread.Sheets.Tables.TableManager#constructor)

### Methods

- [add](GC.Spread.Sheets.Tables.TableManager#add)
- [addFromDataSource](GC.Spread.Sheets.Tables.TableManager#addfromdatasource)
- [all](GC.Spread.Sheets.Tables.TableManager#all)
- [convertFromDataTable](GC.Spread.Sheets.Tables.TableManager#convertfromdatatable)
- [convertToDataTable](GC.Spread.Sheets.Tables.TableManager#converttodatatable)
- [find](GC.Spread.Sheets.Tables.TableManager#find)
- [findByName](GC.Spread.Sheets.Tables.TableManager#findbyname)
- [move](GC.Spread.Sheets.Tables.TableManager#move)
- [remove](GC.Spread.Sheets.Tables.TableManager#remove)
- [resize](GC.Spread.Sheets.Tables.TableManager#resize)

## Constructors

### <a id="constructor" name="constructor"></a> constructor

• **new TableManager**(`sheet`)

Represents a table manager that can manage all tables in a sheet.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `sheet` | [`Worksheet`](GC.Spread.Sheets.Worksheet) | The worksheet. |

## Methods

### <a id="add" name="add"></a> add

▸ **add**(`name?`, `row?`, `column?`, `rowCount?`, `columnCount?`, `style?`): [`Table`](GC.Spread.Sheets.Tables.Table)

Adds a range table with a specified size to the sheet.

**`example`**
```javascript
//This example adds a table.
activeSheet.tables.add("Table1", 0, 0, 3, 3, 'dark1');
activeSheet.getCell(0,0).text("Name");
activeSheet.getCell(0,1).text("Value");
activeSheet.getCell(0,2).text("T/F");
activeSheet.getCell(1,0).text("AW");
activeSheet.getCell(1,1).text("5");
activeSheet.getCell(1,2).text("T");
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name?` | `string` | The table name. |
| `row?` | `number` | The row index. |
| `column?` | `number` | The column index. |
| `rowCount?` | `number` | The row count of the table. |
| `columnCount?` | `number` | The column count of the table. |
| `style?` | `string` \| [`TableTheme`](GC.Spread.Sheets.Tables.TableTheme) | The style of the table. |

#### Returns

[`Table`](GC.Spread.Sheets.Tables.Table)

The new table instance.

___

### <a id="addfromdatasource" name="addfromdatasource"></a> addFromDataSource

▸ **addFromDataSource**(`name`, `row`, `column`, `dataSource`, `style`, `options?`): [`Table`](GC.Spread.Sheets.Tables.Table) \| `Promise`<[`Table`](GC.Spread.Sheets.Tables.Table)\>

Adds a range table with a specified data source to the sheet.

**`example`**
```javascript
var source = [
                { LastName: "Freehafer", FirstName: "Nancy", Title: "Sales Representative", Phone: "(123)555-0100"},
                { LastName: "Cencini", FirstName: "Andrew", Title: "Vice President, Sales", Phone: "(123)555-0101"},
                { LastName: "Kotas", FirstName: "Jan", Title: "Sales Representative", Phone: "(123)555-0102"},
                { LastName: "Sergienko", FirstName: "Mariya", Title: "Sales Representative", Phone: "(123)555-0103"},
            ];
 activeSheet.tables.addFromDataSource("Table1", 5, 2, source, GC.Spread.Sheets.Tables.TableThemes.dark1);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The table name. |
| `row` | `number` | The row index. |
| `column` | `number` | The column index. |
| `dataSource` | `string` \| `Object` \| [`Table`](GC.Data.Table) | The data source for the table. |
| `style` | [`TableTheme`](GC.Spread.Sheets.Tables.TableTheme) | The style of the table. |
| `options?` | [`ITableOptions`](../interfaces/GC.Spread.Sheets.Tables.ITableOptions) | - |

#### Returns

[`Table`](GC.Spread.Sheets.Tables.Table) \| `Promise`<[`Table`](GC.Spread.Sheets.Tables.Table)\>

The new table instance.

___

### <a id="all" name="all"></a> all

▸ **all**(): [`Table`](GC.Spread.Sheets.Tables.Table)[]

Gets all tables of the sheet.

#### Returns

[`Table`](GC.Spread.Sheets.Tables.Table)[]

The GC.Spread.Sheets.Tables.Table array of table instances. The array is never null.

___

### <a id="convertfromdatatable" name="convertfromdatatable"></a> convertFromDataTable

▸ **convertFromDataTable**(`table`): [`Table`](GC.Spread.Sheets.Tables.Table)

Converts the table binding a data manager table to a regular table.

**`example`**
```javascript
var table  = activeSheet.tables.find(0,0);
activeSheet.tables.convertFromDataTable(table);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `table` | `string` \| [`Table`](GC.Spread.Sheets.Tables.Table) | The table instance or the table name. |

#### Returns

[`Table`](GC.Spread.Sheets.Tables.Table)

___

### <a id="converttodatatable" name="converttodatatable"></a> convertToDataTable

▸ **convertToDataTable**(`table`): [`Table`](GC.Spread.Sheets.Tables.Table)

Convert a regular table to the table creating and binding a data manager table.

**`example`**
```javascript
var table  = activeSheet.tables.find(0,0);
activeSheet.tables.convertToDataTable(table);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `table` | `string` \| [`Table`](GC.Spread.Sheets.Tables.Table) | The table instance or the table name. |

#### Returns

[`Table`](GC.Spread.Sheets.Tables.Table)

___

### <a id="find" name="find"></a> find

▸ **find**(`row`, `column`): [`Table`](GC.Spread.Sheets.Tables.Table)

Gets the table of the specified cell.

**`example`**
```javascript
//This example uses the find method.
activeSheet.tables.add("Table1", 0, 0, 3, 3, GC.Spread.Sheets.Tables.TableThemes.dark1);
activeSheet.getCell(0,0).text("Name");
activeSheet.getCell(0,1).text("Value");
activeSheet.getCell(0,2).text("T/F");
activeSheet.getCell(1,0).text("AW");
activeSheet.getCell(1,1).text("5");
activeSheet.getCell(1,2).text("T");
//button click
$("#button1").click(function () {
     var table  = activeSheet.tables.find(0,0);
     console.log(table.name());
});
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `row` | `number` | The row index. |
| `column` | `number` | The column index. |

#### Returns

[`Table`](GC.Spread.Sheets.Tables.Table)

The table instance if the cell belongs to a table; otherwise, null.

___

### <a id="findbyname" name="findbyname"></a> findByName

▸ **findByName**(`name`): [`Table`](GC.Spread.Sheets.Tables.Table)

Gets the table with a specified name.

**`example`**
```javascript
//This example finds the table by name.
var activeSheet = spread.getActiveSheet();
activeSheet.tables.add("Table1", 0, 0, 3, 3, GC.Spread.Sheets.Tables.TableThemes.dark1);
activeSheet.getCell(0,0).text("Name");
activeSheet.getCell(0,1).text("Value");
activeSheet.getCell(0,2).text("T/F");
activeSheet.getCell(1,0).text("AW");
activeSheet.getCell(1,1).text("5");
activeSheet.getCell(1,2).text("T");
// button click
$("#button1").click(function () {
     var table  = activeSheet.tables.findByName("Table1");
     console.log(table.name());
});
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The table name. |

#### Returns

[`Table`](GC.Spread.Sheets.Tables.Table)

The table instance if the cell belongs to a table; otherwise, null.

___

### <a id="move" name="move"></a> move

▸ **move**(`table`, `row`, `column`): `void`

Changes the table location.

**`example`**
```javascript
var activeSheet = spread.getActiveSheet();
activeSheet.tables.add("Table1", 0, 0, 3, 3, GC.Spread.Sheets.Tables.TableThemes.dark1);
activeSheet.getCell(0,0).text("Name");
activeSheet.getCell(0,1).text("Value");
activeSheet.getCell(0,2).text("T/F");
activeSheet.getCell(1,0).text("AW");
activeSheet.getCell(1,1).text("5");
activeSheet.getCell(1,2).text("T");
// button click
$("#button1").click(function () {
     var table  = activeSheet.tables.findByName("Table1");
     alert(table);
     activeSheet.tables.move(table, 3, 3);
});
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `table` | `string` \| [`Table`](GC.Spread.Sheets.Tables.Table) | The table instance or the table name. |
| `row` | `number` | The new row index. |
| `column` | `number` | The new column index. |

#### Returns

`void`

___

### <a id="remove" name="remove"></a> remove

▸ **remove**(`table`, `options`): [`Table`](GC.Spread.Sheets.Tables.Table)

Removes a specified table.

**`example`**
```javascript
var table  = activeSheet.tables.find(0,0);
activeSheet.tables.remove(table, GC.Spread.Sheets.Tables.TableRemoveOptions.keepData);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `table` | `string` \| [`Table`](GC.Spread.Sheets.Tables.Table) | The table instance or the table name. |
| `options` | [`TableRemoveOptions`](../enums/GC.Spread.Sheets.Tables.TableRemoveOptions) | Specifies what data is kept when removing the table. |

#### Returns

[`Table`](GC.Spread.Sheets.Tables.Table)

___

### <a id="resize" name="resize"></a> resize

▸ **resize**(`table`, `range`): `void`

Changes the table size.

**`example`**
```javascript
//This example resizes the table.
activeSheet.tables.add("Table1", 0, 0, 3, 3, GC.Spread.Sheets.Tables.TableThemes.dark1);
activeSheet.getCell(0,0).text("Name");
activeSheet.getCell(0,1).text("Value");
activeSheet.getCell(0,2).text("T/F");
activeSheet.getCell(1,0).text("AW");
activeSheet.getCell(1,1).text("5");
activeSheet.getCell(1,2).text("T");
//button click
$("#button1").click(function () {
     var table  = activeSheet.tables.find(0,0);
     activeSheet.tables.resize(table, new GC.Spread.Sheets.Range(0,0,4,4));
});
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `table` | `string` \| [`Table`](GC.Spread.Sheets.Tables.Table) | The table or the table name. |
| `range` | [`Range`](GC.Spread.Sheets.Range) | The new table range. The headers must remain in the same row, and the resulting table range must overlap the original table range. |

#### Returns

`void`
