useCellSelection hook

Gives you access to the cell selection in the current view.

Note

For getting the selected rows, use the useRowSelection hook.

The return type of this hook is an object with the following properties:

  • columnIds - an array of column ids for the selected cells. Your selection might not be contiguous, and doesn't have to be, but this array contains the ids of all columns that have at least one selected cell.
  • positions - an array of arrays. Each item in the array is in turn an array, and the array items correspond to the columnIds above. Each item in the inner array represents a row that has selection. In any given row, not all cells specified in the columnIds array might be selected, so for the cells that don't have selection, you'll have an empty string or null. For the cells that do have selection, you'll have an object with the following (for each cell):
    • rowId - the id of the row that has the selected cell.
    • value - the value of the selected cell.
    • columnId - the id of the column that has the selected cell.
    • columnDataType - the data type of the column that has the selected cell.
useCellSelection return type
{
  columnIds: ['name', 'github_stars','language'],
  positions: [
    [
       { rowId: 'row1', value: 'React', columnId: 'name', columnDataType: 'string' },
       { rowId: 'row1', value: 1000, columnId: 'github_stars', columnDataType: 'number' },
       '', // the language column doesn't have a selected cell in this row
    ],
    [
        { rowId: 'row3', value: 'Angular', columnId: 'name', columnDataType: 'string' },
        '', // the github_stars column doesn't have a selected cell in this row
        { rowId: 'row3', value: 'TypeScript', columnId: 'language', columnDataType: 'string' },
    ]
  ]
}

Note

You can also use the AdaptableState object (eg via the useAdaptableState hook) to get the selected cells (rowId and columnId combination), but this hooks makes it easier.

Example of how to use useCellSelection
import { useCellSelection } from '@adaptabletools/adaptable-infinite-react';

function YourCmp() {
  const cellSelection = useCellSelection();

  if (!cellSelection) {
    return 'No cell selection!';
  }

  const { columnIds, positions } = cellSelection;

  return <Chart options={positions.map(row => ...)} />
}

function App() {
  return <Adaptable.Provider {...}>
    <YourCmp />
    <Adaptable.UI />
  <

Demo on how to leverage useCellSelection hook
Fork

This example shows how to leverage useCellSelection to access the selected cells and values from the current view.

Select Framework Name for the X Axis column. Select github_stars for the Y Axis column. If you have a cell selection selecting cells from the first 2 columns, you will see the chart.