Skip to content

Error handling ​

Errors come in two kinds. An invalid call throws a GridError. An exception thrown by your own callback is swallowed by the grid and reported through the error event.

The error class is documented in the API reference as GridError.

How invalid input is rejected ​

Wrong shapes in options, columns, rows or models throw invalid-option (never a bare TypeError) and leave the grid state unchanged.

  • Unknown keys: a typo such as rowHeigth is reported with the closest known key in error.hint and the message (Did you mean "rowHeight"?). Applies to options, column definitions, messages, filter/sort items and transactions. Saved columnState ignores unknown properties so newer saves still load.
  • Types and ranges: rowHeight: 0, width: -1, align: 'left' report the path (columns[1].width) and the received value.
  • Rows: a non-array rows or null/primitive rows are rejected. addRows works with very large inputs (200k rows).
  • Prototype pollution guard: __proto__, constructor and prototype cannot be used as a column id/key, rowKey, or as a column id in sort, filter or column state. Read such a data property with getValue.
  • Circular references: model and value comparison terminates on circular filter or cell values.
  • Language: messages follow locale (ko/en); see Language of error messages. Branch on code.

Branch on GridError codes ​

message is a sentence in the grid's locale (ko or en) and may change. Branch on code.

ts
import { GridError } from '@maxgrid/core';

try {
  api.setOptions({ rows });
} catch (error) {
  if (error instanceof GridError && error.code === 'duplicate-row-key') {
    showToast('Two rows share the same employee ID.');
    return;
  }
  throw error;
}
codeWhen it is thrown
duplicate-row-keyTwo rows share a row key
missing-row-keyA row key is undefined, null or an object
duplicate-column-idTwo columns share an id
invalid-optionA column id is empty, a sort or filter model is invalid, and similar
destroyedYou call an API that changes data or options after destroy()
not-implementedReserved value. No method throws this error today

State is unchanged when an error is thrown. setOptions, setSortModel and setFilterModel keep the existing value if validation fails, and transact rolls everything back if one step fails.

How is HTML handled? ​

The grid puts cell values into the DOM as text (textContent) only. A value containing <script> or <img onerror=...> is shown as text and never runs. Turn on cellRenderer: 'html' explicitly only for columns that need markup. That renderer draws only what passed an allowlist sanitizer and removes tags, attributes and addresses outside the list. The rules are in HTML in the built-in renderers.

Language of error messages ​

The message of a GridError, the message of an error event, console notes and the text of an error cell all follow the grid's locale ('ko' by default, or 'en'). Every message lives in one table as a Korean and English pair, so one language cannot be left out.

Wherelocale: 'ko'locale: 'en'
Thrown error존재하지 않는 컬럼입니다: "zz"Column does not exist: "zz"
error event컬럼 "qty"의 집계에서 … 건너뛰었습니다.Aggregation of column "qty" skipped …
Error cell⚠ 오류⚠ Error
Console note[grid] … 오류로 표시합니다.[grid] … shown as an error.
  • Changing locale with setOptions({ locale }) applies to the errors that happen afterwards.
  • Exports are called separately from the grid, so pass the option yourself: exportCsv(api, { locale: 'en' }). Without it the text is Korean.
  • Only developer diagnostics stay Korean whatever the locale: internal state checks in development and test mode (invariant-violation), module-error raised while the grid assembles its own features, and exceptions for misusing a wrapper (a cell helper used outside <mx-grid>, for example). These are not errors your input causes in production.
  • message may change. Branch on code.

Receive the error event ​

If getValue, formatValue, cellClass or rowClass throws, the grid keeps rendering. You cannot catch these errors with try/catch, so listen for the error event.

ts
api.on('error', ({ code, message, cause, where }) => {
  // where, for example: 'getValue(salary)'
  reportToMyLogger({ code, message, where, cause });
});
codeDelivered when
callback-errorOne of your callbacks threw
reentrancy-limitHandlers keep calling the API and the event chain passes 16 levels
module-errorCleaning up an internal part of the grid failed. Your input did not cause it
invariant-violationAn internal state check failed in development or test mode. Not in production bundles
  • A cell whose getValue threw is treated as empty: it sorts last, and filters apply the empty-value rules.
  • A cell whose formatValue or similar threw shows ⚠ 오류 (⚠ Error with locale: 'en'). Other cells and rows are fine.
  • A callback that throws on each of 100,000 rows does not flood you with events. Within one computation, the same where is reported once, and message includes the count. cause is the first value thrown.
  • cause is not always an Error.
  • If you see reentrancy-limit, look for a handler that keeps setting the same model again.

An exception thrown by an event handler does not block other handlers. It is logged with console.error.

ts
api.on('rowClicked', () => {
  throw new Error('my handler failed');
});
api.on('rowClicked', ({ rowKey }) => console.log(rowKey)); // still called

Clean up a grid ​

Call destroy() when you no longer need the grid.

ts
const api = createGrid(container, options);
api.destroy();
api.isDestroyed(); // true
  • destroyed fires and every listener added with on is removed. The DOM and any scheduled render are cleaned up.
  • A second call is ignored.
  • After that, mutating methods such as setRows and setOptions throw GridError('destroyed').
  • The React, Vue and Angular wrappers call it automatically when the component goes away.
  • Timers and external subscriptions your app created are yours to clean up.

Several grids on one page ​

Create each grid in its own container. Grids do not share state or events, so changing one leaves the others alone. Import the theme CSS once.

tsx
<div style={{ height: 240 }}>
  <Grid options={ordersOptions} />
</div>
<div style={{ height: 240 }}>
  <Grid options={customersOptions} />
</div>

Do not call createGrid twice on the same container. Keep one api per grid.