JavaScript Data GridGrid Interface

This section details the public interface that your application can use to interact with the grid, including methods, properties and events.

The grid interface is the combination of the following items:

  • Grid Options: properties and callbacks used to configure the grid, e.g. pagination = true and getRowHeight(params).
  • Grid API: methods used to interact with the grid after it's created, e.g. api.getSelectedRows().
  • Grid Events: events published by the grid to inform applications of changes in state, e.g. rowSelected.
  • Row Node: each row in the grid is represented by a Row Node object, which in turn has a reference to the piece of row data provided by the application. The Row Node wraps the row data item. The Row Node has attributes, methods and events for interacting with the specific row e.g. rowNode.setSelected(true).

Grid Options

The gridOptions object is a 'one stop shop' for the entire interface into the grid. The GridOptions interface supports a generic parameter for row data as detailed in Typescript Generics.

The example below shows the different types of items available on gridOptions.

var gridOptions = {
    // Objects like myRowData and myColDefs would be created in your application
    rowData: myRowData,
    columnDefs: myColDefs,
    pagination: true,
    rowSelection: 'single',

    // EVENTS
    // Add event handlers
    onRowClicked: event => console.log('A row was clicked'),
    onColumnResized: event => console.log('A column was resized'),
    onGridReady: event => console.log('The grid is now ready'),

    getRowHeight: (params) => 25

Once the grid is initialised, you will also have access to the grid API (api) and column API (columnApi) on the gridOptions object as shown:

// refresh the grid

// resize columns in the grid to fit the available space

Access the Grid & Column API

The Grid API (both api and columnApi) will only be available after the gridReady event has been fired.

You can access the APIs in the following ways:

  • Store them from the gridReady event - they'll be available via the params argument passed into the event
  • Provide a gridOptions object to the grid pre-creation time. Post-creation the APIs will be available on the gridOptions object.

Listening to Events

In addition to adding event listeners directly via the gridOptions object, it is possible to register for events, similar to registering for events on native DOM elements. This means there are two ways to listen for events: either use the onXXX() method on the API (where XXX is replaced with the event name), or register a listener for the event. The latter option allows you to add multiple handlers for the same event. The following example demonstrates the two options:

// create handler function
function myRowClickedHandler(event) {
    console.log('The row was clicked');

// option 1: use the API
gridOptions.onRowClicked = myRowClickedHandler;

// option 2: register the handler
gridOptions.api.addEventListener('rowClicked', myRowClickedHandler);

Events Are Asynchronous

Grid events are asynchronous so that the state of the grid will be settled by the time your event callback gets invoked.

Default Boolean Properties

Where the property is a boolean (true or false), then false (or left blank) is the default value. For this reason, on / off items are presented in a way that causes the most common behaviour to be used when the value is false. For example, suppressCellFocus is named as such because most people will want cell focus to be enabled.

Next Steps

That's it, Doc! Now you know how to interface with the grid. Go now and find out about all the great options, methods and events you can use.