Grid Events
LyteNyte Grid fires events in response to specific user interactions or when imperative API methods run. For example, when a cell enters edit mode, the grid fires the editBegin event.
This guide explains how to respond to events from LyteNyte Grid and shows methods to trigger events imperatively when needed.
For a complete list of available events and their triggers, see the Events API Reference Page.
Listening to Events
The Grid.Root component accepts event listeners for all events LyteNyte
Grid may fire. Add listeners as you would any other props in React. This
familiar approach is the recommended way to add event listeners.
Furthermore, like native events, some events have a preventDefault property
that will stop the default action of that event from happening. For example,
we can prevent odd rows from being selected by listening to the rowSelectBegin
event and calling preventDefault when it fires.
Event Listener
The api.eventAddListener Method
Sometimes you may need to add an event listener to LyteNyte Grid outside
a render function. Use the api.eventAddListener method in such cases.
This method adds a listener for the specified event and returns a
function to remove it. You can also call api.eventRemoveListener to
remove a listener explicitly.
When using api.eventAddListener, you must handle cleanup yourself. The
example below demonstrates correct usage with proper cleanup.
Imperative Event Listeners
Triggering Events
The LyteNyte Grid API provides the eventFire method, which lets you
manually trigger an event as if it originated from the grid. This is
useful when building custom functionality that mimics grid event
behavior, but you should avoid it unless necessary.
Grid Reactivity
LyteNyte Grid follows declarative principles. Its state system stays fully reactive, automatically keeping the view synchronized with state changes. This aligns with React's core philosophy that "view is a function of state."
Columns
LyteNyte Grid uses columns to power core features like sorting, filtering, moving, and resizing. When you call the `useLyteNyte` hook, you provide an array of column definitions. This guide explains how to define columns and describes each property.