abhinav saxena
abhinav saxena

Reputation: 11

How to select column data in ag-grid

I have to enable columns selection and perform operation like export Excel/copy to clipboard on particular columns selected. The requirement is when I click on column header it should select the entire column. How can this be achieved?

Upvotes: 1

Views: 1200

Answers (1)

Jonny Wolfson
Jonny Wolfson

Reputation: 121

There are a few ways to do it.

One would be to add a new 'Select Column' entry to the Column Menu and then in the Action create a new cell range. Something like this should do the trick:

var gridOptions = {
 ....
  getMainMenuItems: getMainMenuItems,
 ....
}

function getMainMenuItems(params) {
 var menuItems = params.defaultItems.slice(0);
 menuItems.push({
   name: 'Select Column',
   action: function () {
     gridOptions.api!.clearRangeSelection();
     const cellRangeParams: CellRangeParams = {
       rowStartIndex: 0,
       rowEndIndex: gridOptions.api!.getDisplayedRowCount(),
       columnStart: params.column.getId(),
       columnEnd: params.column.getId(),
   };
   gridOptions.api!.addCellRange(cellRangeParams);
  },
 });
 return menuItems;
}

Upvotes: 2

Related Questions