Skip to main content

Events

This document describes all events emitted by canvas-datagrid. Use the sidebar to the right to quickly find the event you're looking for.

Listening for events can be done by registering a listener:

const grid = canvasDatagrid();

function renderTextHandler(e) {
// your code here; 'e' is the event object
}

grid.addEventListener('rendertext', renderTextHandler);

Don't forget to stop listening when you destroy the grid:

grid.removeEventListener('rendertext', renderTextHandler);

All events

afterdelete

Fires when the selected is deleted by pressing backspace or delete key.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.cellsarrayCells affected by the delete action. Each item in the array is a tuple of [rowIndex, columnIndex, boundRowIndex, boundColumnIndex].

afterpaste

Fires after a paste is performed.

Property nameTypeDescription
eobjectEvent object
e.ctxobjectCanvas context.
e.cellsarrayCells affected by the paste action. Each item in the array is a tuple of [rowIndex, columnIndex, boundRowIndex, boundColumnIndex].

afterrendercell

Fires just after a cell is drawn. If you want to draw things in the cell, this is the event to attach to. Drawing on the canvas is allowed. Altering the context of the canvas is allowed.

Property nameTypeDescription
eobjectEvent object
e.ctxobjectCanvas context.
e.valueobjectCurrent cell value.
e.rowobjectCurrent row data.
e.headerobjectCurrent header object.
e.cellcanvasDatagrid.cellCurrent cell.
e.xobjectThe current cells x coordinate.
e.yobjectThe current cells y coordinate.

appendeditinput

Fires when the edit input is appended to the body. This allows you to intercept the event and by calling e.preventDefault you can prevent the input from being appended to the body. You can then append the input where you like. The input is by default absolutely positioned to appear over the cell. All styles are in-line. You can alter anything you like, dimensions, appearance, parent node. If you run e.preventDefault, and stop the input from being added to the body, make sure you append the input somewhere or you will not be able to use it. When editing is complete the input will remove itself.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.inputobjectThe edit input. You're free to do what you will with it. It will remove itself when editing is complete.

attributechanged

Fires when an attribute has been changed.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.

beforebeginedit

Fires before a edit cell has been created giving you a chance to abort it. e.preventDefault(); will abort the edit cell from being created.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.cellcanvasDatagrid.cellCell object.

beforecreatecellgrid

Fires just before a cell grid is created giving you a chance to abort the creation of the cell grid by calling e.preventDefault(). You can alter cell grid instantiation arguments in this event as well. Only fires once per grid creation.

Property nameTypeDescription
eobjectEvent object
e.ctxobjectCanvas context.
e.valueobjectCurrent cell value.
e.rowobjectCurrent row data.
e.cellGridAttributesobjectMutable cell grid instantiation arguments.
e.headerobjectCurrent header object.
e.cellcanvasDatagrid.cellCurrent cell.
e.xobjectThe current cells x coordinate.
e.yobjectThe current cells y coordinate.

beforeendedit

Fires just before edit is complete giving you a chance to validate the input. e.preventDefault(); will cause the edit to not end and row data will not be written back to the data array.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.cellcanvasDatagrid.cellCurrent cell.
e.newValueobjectNew value.
e.oldValueobjectOld value.
e.abortfunctionAbort edit function. Call this function to abort the edit.
e.inputobjectTextarea or input HTMLElement depending on attributes.multiLine.

beforepaste

Fires before a paste is performed.

Property nameTypeDescription
eobjectEvent object
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.NativeEventobjectNative paste event.

beforerendercell

Fired just before a cell is drawn onto the canvas. e.preventDefault(); prevents the cell from being drawn. You would only use this if you want to completely stop the cell from being drawn and generally muck up everything.

Property nameTypeDescription
eobjectEvent object
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.valueobjectCurrent cell value.
e.rowobjectCurrent row data.
e.headerobjectCurrent header object.

beforerendercellgrid

Fires just before a cell grid is drawn giving you a chance to abort the drawing of the cell grid by calling e.preventDefault(). Only fires once per grid drawing.

Property nameTypeDescription
eobjectEvent object
e.ctxobjectCanvas context.
e.valueobjectCurrent cell value.
e.rowobjectCurrent row data.
e.headerobjectCurrent header object.
e.cellcanvasDatagrid.cellCurrent cell.
e.xobjectThe current cells x coordinate.
e.yobjectThe current cells y coordinate.

beforesortcolumn

Fires just before a column is sorted. Calling e.preventDefault will prevent sorting. Used in conjunction with grid.orderBy and grid.orderDirection you can implement server side ordering while still using the native order by arrows.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.columnNameobjectName of the column.
e.directionobjectDirection of the order.

beforetouchmove

Fires just before a touch move event occurs allowing you to cancel the default behavior of touchmove.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.NativeEventobjectNative touchmove event.

beginedit

Fires when an editor textarea (or input) has been created.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.cellcanvasDatagrid.cellCell object.
e.inputobjectTextarea or input HTMLElement depending on attributes.multiLine.

beginfreezemove

Fires when a freeze cutter begins to move. Calling e.preventDefault will prevent the move from starting.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.

beginmove

Fires when a selection begins to move. Calling e.preventDefault will prevent the move from starting.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.

cellmouseout

Fires when the mouse exits a cell.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.cellcanvasDatagrid.cellThe cell being moved out of.

cellmouseover

Fires when the mouse enters a cell.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.cellcanvasDatagrid.cellThe cell being moved over.

click

Fires when the grid is clicked.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.cellcanvasDatagrid.cellCell object.

collapsetree

Fires when the user click the "drill in" arrow on a row that is already expanded.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.childGridobjectNew, or if reopened existing, grid.
e.dataobjectThe row's data.
e.rowIndexobjectThe row index that was expanded.

columnhide

Fires column(s) are being hidden

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.columnIndexcolumnIndexIndex of column being hidden.

columnmouseout

Fires when the mouse exits a column.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.cellcanvasDatagrid.cellThe cell being moved out of.

columnmouseover

Fires when the mouse enters a column.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.cellcanvasDatagrid.cellThe cell being moved over.

columnunhide

Fires column(s) are being unhidden

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.columnIndexcolumnIndexIndex of column being unhidden.

contextmenu

Fires when a context menu is requested. The menu item array can be altered to change what items appear on the menu. You can add items to the context menu but they must conform to {@link canvasDatagrid.contextMenuItem}. Removing all items from the list of menu items will cause the context menu to not appear. Calling e.preventDefault(); will cause the context menu to not appear as well.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.NativeEventobjectNative contextmenu event.
e.cellcanvasDatagrid.cellCell under mouse.
e.itemsobjectMutable list of menu items.
e.contextMenuobjectContext menu HTML element.

copy

Fires when a copy is performed.

Property nameTypeDescription
eobjectEvent object
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.NativeEventobjectNative copy event.

copyonschema

Fires when a copy is processing on a schema column. If you want to change headers of the copied data, this is the event to attach to. Changing column.title or column.name will not change actual schema, it will just take effect and apply to the copied data.

Property nameTypeDescription
eobjectEvent object
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.NativeEventobjectNative copy event.
e.columnobjectCurrent column object of schema.

datachanged

Fires when the data setter is set.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.dataobjectData.

dblclick

Fires when the mouse button is double clicked on the grid. e.preventDefault(); will abort the default grid event. Note that this will necessarily require 2mousedown, 2mouseup and 2*click events to fire prior to the double click.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.NativeEventobjectNative dblclick event.
e.cellcanvasDatagrid.cellCell object.

endedit

Fires when the edit has ended. This event gives you a chance to abort the edit preserving original row data, or modify the value of the row data prior to being written.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.cellcanvasDatagrid.cellCell object.
e.valueobjectNew value.
e.abortobjectWhen true, the edit was aborted.
e.inputobjectTextarea or input HTMLElement depending on attributes.multiLine.

endfreezemove

Fires when a freeze cutter is dropped. Calling e.preventDefault will prevent the drop from occurring.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.

endmove

Fires when a selection moving selection is dropped. Calling e.preventDefault will prevent the drop from occurring.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.

expandtree

Fires when the user clicks on the "drill in" arrow. When the arrow is clicked a new grid is created and nested inside of the row. The grid, the row data and row index are passed to the event listener. From here you can manipulate the inner grid. A grid is not disposed when the tree is collapsed, just hidden, but grids are not created until the arrow is clicked.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.treeGridobjectNew, or if reopened existing, grid.
e.dataobjectThe row's data.
e.rowIndexobjectThe row index that was expanded.

formattext

Fires when text is about to be formatted. You can stop the default formatting function, text wrap, from occurring by calling e.preventDefault. You might do this to improve performance on very long values (e.g.: lists of numbers not requiring formatting) or to replace the default formatting function with your own. When preventing default it is important to populate the e.cell.text property with a text line array that looks like this { lines: [{value: "line 1" }, {value: "line 2" }] }. Each item in the array is assumed to fit the width of the cell. The total number of lines is assumed to fit into the height of the cell.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.

freezemoving

Fires when the mouse moves while moving a freeze cutter. Calling e.preventDefault will prevent the freeze cutter from moving.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.

keydown

Fires when the keyboard button is pressed down on the grid. e.preventDefault(); will abort the default grid event.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.NativeEventobjectNative keydown event.
e.cellcanvasDatagrid.cellCell object.

keypress

Fires when the keyboard press is completed on the grid. e.preventDefault(); will abort the default grid event.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.NativeEventobjectNative keypress event.
e.cellcanvasDatagrid.cellCell object.

keyup

Fires when the keyboard button is released on the grid. e.preventDefault(); will abort the default grid event.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.NativeEventobjectNative keyup event.
e.cellcanvasDatagrid.cellCell object.

mousedown

Fires when the mouse button is pressed down on the grid. e.preventDefault(); will abort the default grid event.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.NativeEventobjectNative mousedown event.
e.cellcanvasDatagrid.cellCell object.

mousemove

Fires when the mouse moves over the grid.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.cellcanvasDatagrid.cellCell under mouse.

mouseup

Fires when the mouse button is pressed down on the grid. e.preventDefault(); will abort the default grid event.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.NativeEventobjectNative mouseup event.
e.cellcanvasDatagrid.cellCell object.

mousewheel

Fires when a mouseweel event occurs.

Property nameTypeDescription
eobjectEvent object
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.NativeEventobjectNative mouseweel event.

moving

Fires when the mouse moves while moving a selection. Calling e.preventDefault will prevent the move from occurring.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.

rendercell

Fires when a cell is drawn. If you want to change colors, sizes this is the event to attach to. Changing the cell object's height and width is allowed. Altering the context of the canvas is allowed. Drawing on the canvas will probably be drawn over by the cell.

Property nameTypeDescription
eobjectEvent object
e.ctxobjectCanvas context.
e.valueobjectCurrent cell value.
e.rowobjectCurrent row data.
e.headerobjectCurrent header object.
e.cellcanvasDatagrid.cellCurrent cell.
e.xobjectThe current cells x coordinate.
e.yobjectThe current cells y coordinate.

rendercellgrid

Fires just after a cell grid calls its draw method. Allows you to alter the cell data grid. Only fires once per child grid.

Property nameTypeDescription
eobjectEvent object
e.ctxobjectCanvas context.
e.valueobjectCurrent cell value.
e.rowobjectCurrent row data.
e.headerobjectCurrent header object.
e.cellcanvasDatagrid.cellCurrent cell.
e.xobjectThe current cells x coordinate.
e.yobjectThe current cells y coordinate.

renderorderbyarrow

Fires when the order by arrow is drawn onto the canvas. This is the only way to completely replace the order arrow graphic. Call e.preventDefault() to stop the default arrow from being drawn.

Property nameTypeDescription
eobjectEvent object
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.valueobjectCurrent cell value.
e.rowobjectCurrent row data.
e.headerobjectCurrent header object.
e.cellcanvasDatagrid.cellCurrent cell.
e.xobjectThe current cells x coordinate.
e.yobjectThe current cells y coordinate.

rendertext

Fires when text is drawn into a cell. If you want to change the color of the text, this is the event to attach to. To alter what text finally appears in the cell, change the value of cell.formattedValue. Keep in mind this text will still be subject to the ellipsis function that truncates text when the width is too long for the cell. You cannot alter the cell's height or width from this event, use rendercell event instead.

Property nameTypeDescription
eobjectEvent object
e.ctxobjectCanvas context.
e.valueobjectCurrent cell value.
e.rowobjectCurrent row data.
e.headerobjectCurrent header object.
e.cellcanvasDatagrid.cellCurrent cell.
e.xobjectThe current cells x coordinate.
e.yobjectThe current cells y coordinate.

rendertreearrow

Fires when the tree arrow is drawn onto the canvas. This is the only way to completely replace the tree arrow graphic. Call e.preventDefault() to stop the default arrow from being drawn.

Property nameTypeDescription
eobjectEvent object
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.valueobjectCurrent cell value.
e.rowobjectCurrent row data.
e.headerobjectCurrent header object.
e.cellcanvasDatagrid.cellCurrent cell.
e.xobjectThe current cells x coordinate.
e.yobjectThe current cells y coordinate.

reorder

Fires when the user finishes reordering a column or row. Calling e.preventDefault will prevent the column from being reordered.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.NativeEventobjectNative mousemove event.
e.sourcecellThe header cell of the column or row being reordered.
e.targetcellThe header cell of the column or row that the dragged row or column will be inserted onto.
e.dragModestringWhen dragging a column column-reorder, when dragging a row row-reorder.

reordering

Fires as the user reorders a row or column. Calling e.preventDefault will prevent the column from starting to be reordered.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.NativeEventobjectNative mousemove event.
e.sourcecellThe header cell of the column or row being reordered.
e.targetcellThe header cell of the column or row that the dragged row or column will be inserted onto.
e.dragModestringWhen dragging a column column-reorder, when dragging a row row-reorder.

resize

Fires when grid is being resized.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.

resizecolumn

Fires when a column is about to be resized. e.preventDefault(); will abort the resize.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.xobjectx pixel position of the resize.
e.yobjecty pixel position of the resize.
e.preventDefaultfunctionPrevents the default behavior.
e.cellcanvasDatagrid.cellThe mutable cell to be resized.

rowmouseout

Fires when the mouse exits a row.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.cellcanvasDatagrid.cellThe cell being moved out of.

rowmouseover

Fires when the mouse enters a row.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.cellcanvasDatagrid.cellThe cell being moved over.

schemachanged

Fires when the schema setter is set.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.schemaobjectSchema.

scroll

Fires when the user scrolls the grid.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.topnumberThe new scroll top.
e.leftnumberThe new scroll left.

selectionchanged

Fires when the selection changes.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.selectedDataobjectSelected data.
e.selectionsarraySelections object. 2D matrix of selections.
e.selectionBoundsrectanglerectangle object describing the selection bounds.
e.boundRowIndexMapobjectMapping of view data row to bound data row index.
e.boundColumnIndexMapobjectMapping of view column order to bound column order.

sortcolumn

Fires when a column is sorted.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.columnNameobjectName of the column.
e.directionobjectDirection of the order.

stylechanged

Fires when a style has been changed.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.preventDefaultfunctionPrevents the default behavior.
e.styleNameobjectThe name of the style being changed.
e.styleValueobjectThe value of the style being changed.

touchcancel

Fires when the a touch event is canceled.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.NativeEventobjectNative touchcancel event.

touchend

Fires when the a touch event ends.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.cellcanvasDatagrid.cellLast cell touched by point 0 prior to the touchend event being called.
e.NativeEventobjectNative touchend event.

touchmove

Fires when the a touch move event occurs.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.cellcanvasDatagrid.cellCell being touched.
e.NativeEventobjectNative touchmove event.

touchstart

Fires when the a touch event begins.

Property nameTypeDescription
eobjectEvent object.
e.ctxobjectCanvas context.
e.NativeEventobjectNative touchstart event.
e.cellcanvasDatagrid.cellCell object.