Skip to content

Commit

Permalink
Merge pull request #348 from SandroHc/expose-column-info
Browse files Browse the repository at this point in the history
Expose column data in Column API
  • Loading branch information
johanneswilm authored Nov 20, 2023
2 parents a50b924 + 55ea34e commit 9943c24
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/demos/dist/module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/demos/dist/module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/demos/dist/umd.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions docs/documentation/columns-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ You can then chain the following methods.

---

### `get(column [integer])`

Fetch read-only data about the column at index `column`. The `column` parameter should be a non-zero-based integer.

---

### `size()`

Fetch the number of columns.

---

### `sort(column [integer], direction [string])`

Sort the selected column. The `column` parameter should be a non-zero-based integer. The `direction` parameter is optional.
Expand Down
11 changes: 11 additions & 0 deletions src/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ export class Columns {
[this.settings, this._state] = readColumnSettings(this.dt.options.columns, this.dt.options.type, this.dt.options.format)
}

get(column: number) {
if (column < 0 || column >= this.size()) {
return null
}
return {...this.settings[column]}
}

size() {
return this.settings.length
}

/**
* Swap two columns
*/
Expand Down

0 comments on commit 9943c24

Please sign in to comment.