Skip to main content

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

NameDescription
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

NameDescription
afterActionFires after an action is executed
afterClearFires after a spreadsheet is cleared
afterDataLoadedFires after data loading has been completed
afterEditEndFires after editing of a cell is finished
afterEditStartFires after editing of a cell has started
afterFocusSetFires after focus is set on a cell
afterSelectionSetFires after cells are selected
afterSheetChangeFires after the currently active sheet is changed
beforeActionFires before an action is executed
beforeClearFires before a spreadsheet is cleared
beforeEditEndFires before editing of a cell is finished
beforeEditStartFires before editing of a cell has started
beforeFocusSetFires before focus is set on a cell
beforeSelectionSetFires before cells are selected
beforeSheetChangeFires before changing the currently active sheet

Spreadsheet properties

NameDescription
colsCountOptional. Sets the number of columns a spreadsheet will have on initialization
editLineOptional. Shows/hides the editing bar
exportModulePathOptional. Sets the path to the export module
formatsOptional. Defines the list of number formats
importModulePathOptional. Sets the path to the import module
localizationOptional. Defines the format of numbers, dates, time and currency
menuOptional. Shows/hides the menu
multiSheetsOptional. Enables/disables an ability to work with multiple sheets in the spreadsheet
readonlyOptional. Enables/disables the readonly mode
rowsCountOptional. Sets the number of rows a spreadsheet will have on initialization
toolbarBlocksOptional. Specifies blocks of buttons that will be shown in the toolbar of spreadsheet

Sheet Manager methods

NameDescription
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

NameDescription
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

NameDescription
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

NameDescription
json()Exports data from a spreadsheet into a JSON file
xlsx()Exports data from a spreadsheet into an Excel (.xlsx) file