DataGridXL - API

DataGridXL Methods

The Core API gives you full programmatic control over the grid.

Use this for scrolling, selection, editing, and other key tasks.

How to call methods

js
grid.selectCell(3, 0);
grid.updateConfig({ allowEditCells: false });

Methods

activate()

Activate grid. Other DataGridXL instances on the same page will be deactivated. Sets cell cursor position at cell 0,0 unless grid is already active.

activateFullscreen()

Activate fullscreen

clearCellValues(cells)

Clear given cell (range) values (set all values to null).

Arguments

cells
CellCoordsCellRangeCellRangeCollectionCells to clear
clearSearch()

Clear Search

deactivate()

Deactivate grid.

deactivateFullscreen()

Deactivate fullscreen

deleteCols(cols, source?)

Delete Columns. Requires cols to be set.

Arguments

cols
ColCoordColRangeColRangeCollectionColumns to delete
source?
stringdefault "code"Action source
deleteColsById(colIds, source?)

Delete columns by their IDs

Arguments

colIds
ColId[]IDs of columns
source?
stringdefault "code"Action source
deleteRows(rows, source?)

Delete Rows. Requires rows to be set.

Arguments

rows
RowCoordRowRangeRowRangeCollectionRows to delete
source?
stringdefault "code"Action source
deleteRowsById(rowIds, source?)

Delete Rows By Their IDs

Arguments

rowIds
RowId[]IDs of rows
source?
stringdefault "code"Action source
destroy()

Destroy the instance. Removes all event listeners. Frees up memory.

downloadCSV()

Download grid data as CSV file

downloadJSON()

Download grid data as JSON file

fillCells(cellRange, fillDirection, fillAmount)

Fill Cells

Arguments

cellRange
CellRangeCell range to fill from
fillDirection
('up''right''down''left')Direction to fill in
fillAmount
numberAmount of "coords" to fill in given direction
freezeCols(amount?)

Freeze columns. Amount includes any hidden columns. Default amount is 1.

Arguments

amount?
numberdefault 1Amount of columns to freeze (from left)
freezeColsUntilId(colId)

Freeze columns until (and including) given column ID

Arguments

colId
ColIdLast column ID to include in freeze
freezeRows(amount?)

Freeze rows. Amount includes any hidden rows. Default amount is 1.

Arguments

amount?
numberdefault 1Amount of rows to freeze (from top)
freezeRowsUntilId(rowId)

Freeze rows until (and including) given row ID

Arguments

rowId
RowIdLast row ID to include in freeze
getInteractionMode(): ('ready' | 'enter' | 'edit' | 'contextmenu')

Get active interaction mode

Returns('ready''enter''edit''contextmenu')Active interaction mode
getLocalizedValue(value): string

Retrieves localized value

Arguments

value
stringstring to stranslate
ReturnsstringLocalized string
getSpreadsheetCoords(cellCoords): string

Get spreadsheet-style label for given cell coordinates

Arguments

cellCoords
CellCoords
Returnsstringspreadsheet-style label (E.g. "A2", "C23", ...)
getWindowOffset(): object

getWindowOffset

ReturnsobjectWindow scroll offset {x,y}
hideCols(cols)

Hide columns

Arguments

cols
ColCoordColRangeColRangeCollection
hideColsById(colIds)

Hide columns by their IDs

Arguments

colIds
array.<ColId>ids of columns
hideRows(rows)

Hide rows

Arguments

rows
RowCoordRowRangeRowRangeCollection
hideRowsById(rowIds)

Hide rows by their IDs

Arguments

rowIds
array.<RowId>ids of rows
insertEmptyCols(amount?, colCoord?)

Insert empty columns. Inserts at the end by default.

Arguments

amount?
numberdefault 1Amount of empty columns to insert
colCoord?
ColCoordColumn coordinate to insert columns at
insertEmptyColsById(amount?, targetId?)

Insert Empty Columns (after ID)

Arguments

amount?
numberdefault 1Amount of empty columns to insert
targetId?
ColCoordColumn ID to insert columns at
insertEmptyRows(amount?, rowCoord?)

Insert empty rows. Inserts at the end by default.

Arguments

amount?
numberdefault 1how many rows to insert
rowCoord?
RowCoordRow coordinate to insert rows at
insertEmptyRowsById(amount?, targetId?)

Insert Empty Rows (after ID)

Arguments

amount?
numberdefault 1Amount of empty rows to insert
targetId?
ColCoordRow ID to insert rows at
moveCols(cols, colCoord)

Move columns

Arguments

cols
ColCoordColRangeColRangeCollectionColumns to move
colCoord
ColCoordColumn coordinate to move columns after
moveColsById(colIds, targetId, source?)

Move columns by their IDs

Arguments

colIds
ColId[]IDs of columns
targetId
ColIdID of column to move columns after
source?
stringdefault "code"Action source
moveRows(rows, rowCoord)

Move Rows

Arguments

rows
RowCoordRowRangeRowRangeCollectionRows to move
rowCoord
RowCoordRow coordinate to move rows after
moveRowsById(colIds, targetId, source?)

Move rows by their IDs

Arguments

colIds
ColId[]IDs of rows
targetId
ColIdID of row to move rows after
source?
stringdefault "code"Action source
performCopy()

Copy cell selection

performCut()

Cut cell selection

performPaste()

Paste clipboard contents

performSort(colCoord, sortDirection)

Sort by column

Arguments

colCoord
ColCoord
sortDirection
('asc''desc')
redo()

Redo

resizeCols(cols, width?)

Resize columns. When no width is given, column will be resized to fit its contents

Arguments

cols
ColCoordColRangeColRangeCollectioncolumns to resize
width?
numberDesired column width
resizeCols(colIds, width?)

Resize columns. When no width is given, column will be resized to fit its contents

Arguments

colIds
ColId[]column IDs to resize
width?
numberDesired column width
search(searchStr)

Search

Arguments

searchStr
stringstring to search for
searchNext()

Jump to next cell in search result set

searchPrev()

Jump to previous cell in search result set

setCellValues(cells, values, mayExceedCellRange?, cellRangeToCut?)

Set given cell (range) values. If values is a single cell value, it will apply to all cells.

Arguments

cells
CellCoordsCellRangeCellRangeCollectionCells to affect
values
CellValueRangeOfCellValuesValue(s) to write in cells
mayExceedCellRange?
booleandefault falseWhether overflowing cell values are written
cellRangeToCut?
CellRangedefault nullCell Range to clear
setColAlign(colCoord)

Set Column Alignment

Arguments

colCoord
ColCoord
setInteractionMode(interactionMode)

setInteractionMode

Arguments

interactionMode
('ready''enter''edit''contextmenu')
setTheme(theme)

Set Theme

Arguments

theme
objectstringpreset theme (string) or a theme object
showColsById(colIds)

Make columns visible

Arguments

colIds
array.<ColId>ids of columns
showRowsById(rowIds)

Make rows visible

Arguments

rowIds
array.<RowId>ids of rows
toggleCellValues(cells)

Toggle all boolean cell values within given cell range

Arguments

cells
CellCoordsCellRangeCellRangeCollectionCells to toggle true↔false
toggleFullscreen()

toggle fullscreen

undo()

Undo