API overview
Constructor
const spreadsheet = new dhx.Spreadsheet("spreadsheet_container", {
rowsCount: 20,
colsCount: 20
});
Parameters:
- an HTML container (or the ID of an HTML container)
- a hash of config options (check below)
Spreadsheet methods
| Name | Description |
|---|---|
| addColumn() | Adds a new column into the spreadsheet |
| addFormula() | Registers a custom formula function that can be used in cell formulas |
| addRow() | Adds a new row into the spreadsheet |
| clear() | Clears a spreadsheet |
| deleteColumn() | Removes a column from the spreadsheet |
| deleteRow() | Removes a row from the spreadsheet |
| eachCell() | Iterates cells in the spreadsheet |
| endEdit() | Finishes editing in the selected cell, closes editor and saves the entered value |
| fitColumn() | adjusts the width of the column to match the longest value in the column |
| freezeCols() | Fixes ("freezes") columns |
| freezeRows() | Fixes ("freezes") rows |
| getFilter() | Returns an object with criteria specified for data filtering |
| getFormat() | Returns the number format applied to the value of a cell |
| getFormula() | Returns the formula of a cell |
| getStyle() | Returns styles applied to a cell(s) |
| getValue() | Returns the value(s) of a cell(s) |
| hideCols() | Hides columns |
| hideRows() | Hides rows |
| hideSearch() | hides the search bar |
| insertLink() | inserts/removes a hyperlink in a cell |
| isLocked() | Checks whether a cell(s) is(are) locked |
| load() | Loads data from an external file |
| lock() | Locks the specified cell |
| mergeCells() | merges a range of cells into one or splits merged cells |
| parse() | Loads data into spreadsheet from a local data source |
| redo() | Applies the reverted action once again |
| serialize() | Serializes data of spreadsheet into a JSON object |
| search() | searches for cells by the specified parameters |
| setFilter() | Filters data in the spreadsheet by the specified criteria |
| setFormat() | Sets a specified format to the value of a cell |
| setStyle() | Sets style to a cell(s) |
| setValidation() | Sets validation for cells via adding drop-down lists into the cells |
| setValue() | Sets a value for a cell |
| showCols() | Shows hidden columns |
| showRows() | Shows hidden rows |
| startEdit() | Starts editing in the selected cell |
| undo() | Reverts the latest action |
| unfreezeCols() | Unfreezes the fixed ("frozen") columns |
| unfreezeRows() | Unfreezes the fixed ("frozen") rows |
| unlock() | Unlocks a locked cell(s) |
Spreadsheet events
| Name | Description |
|---|---|
| afterAction | Fires after an action is executed |
| afterClear | Fires after a spreadsheet is cleared |
| afterDataLoaded | Fires after data loading has been completed |
| afterEditEnd | Fires after editing of a cell is finished |
| afterEditStart | Fires after editing of a cell has started |
| afterFocusSet | Fires after focus is set on a cell |
| afterSelectionSet | Fires after cells are selected |
| afterSheetChange | Fires after the currently active sheet is changed |
| beforeAction | Fires before an action is executed |
| beforeClear | Fires before a spreadsheet is cleared |
| beforeEditEnd | Fires before editing of a cell is finished |
| beforeEditStart | Fires before editing of a cell has started |
| beforeFocusSet | Fires before focus is set on a cell |
| beforeSelectionSet | Fires before cells are selected |
| beforeSheetChange | Fires before changing the currently active sheet |
Spreadsheet properties
| Name | Description |
|---|---|
| colsCount | Optional. Sets the number of columns a spreadsheet will have on initialization |
| editLine | Optional. Shows/hides the editing bar |
| exportModulePath | Optional. Sets the path to the export module |
| formats | Optional. Defines the list of number formats |
| importModulePath | Optional. Sets the path to the import module |
| localization | Optional. Defines the format of numbers, dates, time and currency |
| menu | Optional. Shows/hides the menu |
| multiSheets | Optional. Enables/disables an ability to work with multiple sheets in the spreadsheet |
| readonly | Optional. Enables/disables the readonly mode |
| rowsCount | Optional. Sets the number of rows a spreadsheet will have on initialization |
| toolbarBlocks | Optional. Specifies blocks of buttons that will be shown in the toolbar of spreadsheet |
Sheet Manager methods
| Name | Description |
|---|---|
| add() | Adds a new empty sheet to the spreadsheet and returns the unique identifier of the newly created sheet |
| clear() | Clears the content of a specific sheet (removes all cell values, styles, and formatting) without deleting the sheet itself |
| get() | Returns a single sheet object by its identifier |
| getActive() | Returns the sheet object that is currently active (visible) in the spreadsheet |
| getAll() | Returns an array of all sheet objects currently present in the spreadsheet |
| remove() | Removes a sheet from the spreadsheet by its identifier |
| setActive() | Switches the active (visible) sheet to the one specified by its identifier |
Selection methods
| Name | Description |
|---|---|
| getFocusedCell() | Returns the id of a focused cell |
| getSelectedCell() | Returns the id(s) of selected cell(s) |
| removeSelectedCell() | Removes selection from the specified cell(s) |
| setFocusedCell() | Sets focus on the specified cell |
| setSelectedCell() | Selects the specified cell(s) |
Events Bus methods
| Name | Description |
|---|---|
| detach() | Detaches a handler from an event (which was attached before by the on() method) |
| fire() | Triggers an inner event |
| on() | Attaches a handler to an inner event of Spreadsheet |
Export methods
| Name | Description |
|---|---|
| json() | Exports data from a spreadsheet into a JSON file |
| xlsx() | Exports data from a spreadsheet into an Excel (.xlsx) file |