A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.ag-grid.com/javascript-data-grid/accessing-data/ below:

JavaScript Grid: Accessing Rows | AG Grid

This section covers the ways data can be accessed once it has been supplied to the grid.

Each time you pass data to the grid, the grid wraps each data item with a Row Node object. For example, if your data has 20 rows, the grid creates 20 Row Node objects, each Row Node wrapping one item of your data.

It is sometimes handy to access these Row Nodes. One example where it is handy is if you want to select a row, you can call rowNode.setSelected(true) to select it. This section details the different ways a Row Node can be accessed.

The following methods are provided for accessing the individual Row Nodes. A deeper explanation of these methods, along with examples, is provided further down.

Accessing Row Node API Methods Copy Link

Function

Returns the row node with the given ID. The row node ID is the one you provide from the callback getRowId(params), otherwise the ID is a number (cast as string) auto-generated by the grid when the row data is set.

Application Assigned IDs RowApiModule

Function

Iterates through each node (row) in the grid and calls the callback for each node. This works similar to the forEach method on a JavaScript array. This is called for every node, ignoring any filtering or sorting applied within the grid. It is not called on any pinned row nodes. If using the Infinite Row Model, then this gets called for each page loaded in the page cache.

Iterating Rows RowApiModule

Function

Similar to forEachNode, except skips any filtered out data.

Iterating Rows ClientSideRowModelApiModule forEachNodeAfterFilterAndSortCopy Link

Function

Similar to forEachNodeAfterFilter, except the callbacks are called in the order the rows are displayed in the grid.

Iterating Rows ClientSideRowModelApiModule

Function

Similar to forEachNode, except lists all the leaf nodes. This effectively goes through all the data that you provided to the grid before the grid performed any grouping. If using tree data, goes through all the nodes for the data you provided, including nodes that have children, but excluding groups the grid created where gaps were missing in the hierarchy.

Iterating Rows ClientSideRowModelApiModule Accessing Rows by Row ID Copy Link

The easiest way to get a Row Node is by its Row ID. The ID is either provided by you using the grid callback getRowId(), or generated by the grid using an internal sequence.

const gridOptions = {
    
    getRowId: params => params.data.id,

    
}

To lookup a Row Node use getRowNode() on the Grid API as follows:


const rowNode = api.getRowNode('55'); 


rowNode.setSelected(true);
Iterating Rows Copy Link

Sometimes you may want to iterate through all the Row Nodes in the grid. This can be done using the grid's iteration APIs. The iteration APIs go through every Row Node, regardless of whether the Row Node is displayed or not. For example, if grouping and the group is closed, the group's children are not displayed by the grid, however the children are included in the iteration 'for-each' methods.


api.forEachNode((rowNode, index) => {
    console.log('node ' + rowNode.data.athlete + ' is in the grid');
});


api.forEachNodeAfterFilter((rowNode, index) => {
    console.log('node ' + rowNode.data.athlete + ' passes the filter');
});


api.forEachNodeAfterFilterAndSort((rowNode, index) => {
    console.log('node ' + rowNode.data.athlete + ' passes the filter and is in this order');
});


api.forEachLeafNode((rowNode, index) => {
    console.log('node ' + rowNode.data.athlete + ' is not a group!');
});

All the methods above work with the Client-Side Row Model, i.e. the default Row Model. For all the other row models (i.e. Viewport, Infinite and Server-Side) the only method that is supported is api.forEachNode() and that will return back Row Nodes that are loaded into browser memory only (as each of these row models use a data source to lazy load rows).

Example Using For-Each Methods Copy Link

The example below shows the different For-Each API methods as follows:

In the example, try applying some sorts and filters, and see how this impacts the different operations in the developer console.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4