Selecting using Grid API Functions

Summary

  • Methods in Grid API allow cells and rows to be selected programatically
  • Cell Ranges, Columns and Rows can all be selected
  • Additionally selection can be done using Expressions

The Grid API section of AdapTable API can be used for both selection and highlighting.

The selection and highlighting related functions include:

  • selecting cell ranges using row indexes, primary key values or AdapTableQL Expressions
  • selecting whole columns
  • unselecting cells or columns

Selecting Ranges

It is straightforward to select a range of Cells in AdapTable by using the selectCellRange function in Grid API.

The range can be uniquely defined in 2 main ways:

  • using row indexes - i.e. the index of the row as currently positioned in the Grid

  • using Primary Key Column values

    Hint

    This ensures the same range is always selected irrespective of current Grid sorting

Selecting Cell Ranges
Fork
  • In this demo we use the range selection methods in Grid API to:
    • select a groups of cells across the Name and Language columns using row index
    • select another group of cells across the Github Stars and License columns using primary keys
    • deselect all selected cells

Expand to see the Grid API methods used

Selecting using Expressions

An alternative way to select Rows and Cells in AdapTable is by an Expression.

The selectCellRangeByQuery function in Grid API receives a Standard Expression.

The Expression is evaluated by AdapTableQL and those rows that match the query are selected.

Note

This means by default the whole Row will be selected if the Query returns true.

Hint

  • To select cells only, pass in a Range to the function
  • Only cells which are contained in that Range will be selected by AdapTable
Selecting using Expressions
Fork
  • In this demo we use the Grid API to select rows and cells using Expressions, (via 5 Custom Toolbar Buttons) as follows:
    • First button selects cells where License is Other - we use a range to limit the selection of cells to just the License column
    • Second button selects whole row where Language is "HTML" (using Expression [language]="HTML")
    • Third button creates a "Big Starts" Range so that the the Name, Github Stars and Github Watchers Columns are selected (using Expression [github_stars]>40000)
    • Fourth button calls ExportApi to run the Selected Data Report sending currently selected data to Excel
    • Final button calls Clear Selection - which clears the current selection

Selecting Columns

There are 2 functions in Grid API which enable Columns in AdapTable to be selected programatically:

  • selectColumn - selects a single Column
  • selectColumns - selects a given array of Columns

Note

  • Both these functions will replace whatever is currently selected

Hint

  • Use the addColumnToSelection function in Column API to programatically add a Column to current selection
Selecting Columns
Fork
  • This example uses the column selection methods in Grid API via 4 Custom Toolbar buttons:
    • First Button selects the Langueage and License columns using selectColumns
    • Second Button selects the Github Watchers column using selectColumn (this replaces the current selection)
    • Third Button selects the Github Stars column using addColumnToSelection in Column API (this keeps the current selection)
    • Fourth Button clears all selected columns

Selecting Rows

There are 4 primary functions in Grid API which enable Rows in AdapTable to be selected programatically:

  • selectRow - selects a single Row (using a Primary Key value)
  • selectRows - selects a given array of Row (using a Primary Key value)
  • selectNode - selects a given AG Grid RowNode
  • selectNodes - selects a given array of AG Grid RowNodes
Selecting Rows
Fork
  • This example demonstrates the Row and RowNode selection methods in Grid API using Custom Toolbar buttons:
    • First Button uses selectRows method to select the 1st and 3rd rows
    • Second Button uses selectNode method to select the 5th row

Selecting Whole Grid

There are 2 functions in Grid API relating to whole Grid selection (or deselection):

  • selectAll - selects everything in the Grid
  • deselectAll - deselects everything in the Grid
Selecting whole Grid
Fork
  • This example provides 2 Custom Toolbar Buttons which call the selectAll and deselectAll functions in Grid API

Selection using AdapTable API

(Recorded with AdapTable v16.2)