RevoGrid Event Patterns and Lifecycles
RevoGrid emits many events, but most application code only needs a few event groups. This guide organizes them by workflow so you can choose the right hook quickly.
Editing lifecycle
Use these events when validating or transforming edits:
beforeeditstart: before the editor opensbeforeedit: before a single-cell value is committedbeforerangeedit: before range data is committedafteredit: after the change has been applied
Typical pattern:
grid.addEventListener('beforeedit', event => {
if (event.detail.prop === 'quantity' && Number(event.detail.val) < 0) {
event.preventDefault();
}
});
grid.addEventListener('afteredit', event => {
console.log('Persist change', event.detail);
});You can also rewrite the value before it is stored:
grid.addEventListener('beforeedit', event => {
if (event.detail.prop === 'name') {
event.detail.val = String(event.detail.val).trim();
}
});Filtering lifecycle
Use these events when you need to inspect or rewrite filter behavior:
beforefilterapplybeforefiltertrimmedaftertrimmed
Typical use cases:
- enforce filter defaults
- add analytics for active filters
- merge app-level visibility rules with filter-driven trimming
Example:
grid.addEventListener('beforefilterapply', event => {
console.log('Incoming filters', event.detail.collection);
});Sorting lifecycle
Sorting emits a sequence of events that is useful when sorting state must stay synchronized with app state:
beforesortingbeforesortingapplybeforesourcesortingapplysortingconfigchanged
Use these for:
- preventing sort changes in some states
- syncing sort state to the URL or store
- observing when a sort transition begins vs when source application happens
Example:
grid.addEventListener('beforesorting', event => {
if (event.detail.column.prop === 'lockedColumn') {
event.preventDefault();
}
});Source update lifecycle
These events are important when your application treats the grid as a view over an external store:
beforesourcesetbeforeanysourceaftersourcesetafteranysource
Typical use cases:
- normalize or enrich incoming rows
- keep pinned and main data updates observable
- trigger persistence or cache updates after the grid source changes
Example:
grid.addEventListener('aftersourceset', event => {
console.log(`Updated source type: ${event.detail.type}`);
});Focus and selection lifecycle
Use these events when keyboard interaction, range behavior, or custom navigation matters:
beforecellfocusbeforefocuslostafterfocusbeforerangebeforeautofill
These are especially important when external controls and the grid must stay synchronized.
Example:
grid.addEventListener('beforefocuslost', event => {
if (hasUnsavedPopover) {
event.preventDefault();
}
});Cancelable vs informational events
The most important distinction:
- cancelable events let you stop or rewrite behavior with
event.preventDefault() - informational events let you react after something already happened
Good rule of thumb:
- validation and policy enforcement go in
before*events - logging, syncing, analytics, and UI side effects go in
after*events
Recommended event combinations
Validate and then persist edits
beforeeditto block invalid writesaftereditto save to your backend or store
Keep URL or store filters in sync
beforefilterapplyto inspect intentaftertrimmedto react once the visible set changed
Synchronize app sort state
beforesortingto allow or deny sort changessortingconfigchangedto update external state