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
- In this demo we use the range selection methods in Grid API to:
- select a groups of cells across the
NameandLanguagecolumns using row index - select another group of cells across the
Github StarsandLicensecolumns using primary keys - deselect all selected cells
- select a groups of cells across the
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
- 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
Licenseis Other - we use a range to limit the selection of cells to just the License column - Second button selects whole row where
Languageis "HTML" (using Expression[language]="HTML") - Third button creates a "Big Starts" Range so that the the
Name,Github StarsandGithub WatchersColumns are selected (using Expression[github_stars]>40000) - Fourth button calls
ExportApito run the Selected Data Report sending currently selected data to Excel - Final button calls
Clear Selection- which clears the current selection
- First button selects cells where
Selecting Columns
There are 2 functions in Grid API which enable Columns in AdapTable to be selected programatically:
selectColumn- selects a single ColumnselectColumns- selects a given array of Columns
Note
- Both these functions will replace whatever is currently selected
Hint
- Use the
addColumnToSelectionfunction in Column API to programatically add a Column to current selection
- This example uses the column selection methods in Grid API via 4 Custom Toolbar buttons:
- First Button selects the
LangueageandLicensecolumns usingselectColumns - Second Button selects the
Github Watcherscolumn usingselectColumn(this replaces the current selection) - Third Button selects the
Github Starscolumn usingaddColumnToSelectionin Column API (this keeps the current selection) - Fourth Button clears all selected columns
- First Button selects the
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 RowNodeselectNodes- selects a given array of AG Grid RowNodes
Selecting Whole Grid
There are 2 functions in Grid API relating to whole Grid selection (or deselection):
selectAll- selects everything in the GriddeselectAll- deselects everything in the Grid