Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ag-grid export select rows by default

I'm using ag-grid (angular) and I would like to export the select rows to CSV or Excel. From what i researched on documentation this feature seems to be possible only using an external button (yellow on image) and not from the export inside of the table (red underline in image).

Is this possible to export selected line through the table itself (red underline in image)?

I'm imagining a multi selection feature in table and if I've no elements selected so the ag-grid export all data and if i've some elements selected then the ag-grid only export the selected one.

enter image description here

like image 738
JMarques Avatar asked Oct 15 '25 20:10

JMarques


1 Answers

This is possible and can be achieved defining your custom function under context menu:

  • indicate that you will customise your Context Menu:
var gridOptions = {
    columnDefs: columnDefs,
    getContextMenuItems: getContextMenuItems,
    rowSelection: 'multiple',
    ...
};
  • define your action exportDataAsExcel and pass onlySelected: true param to reduce export lines:
function getContextMenuItems(params) {
    var result = [
       {
            name: "Excel Export (.xlsx)",
            action: () => params.api.exportDataAsExcel(
              {onlySelected: true}
            )
        },
    ];

    return result;
}
  • you don't need to remove all the menu elements as I did - more about Context Menu can be found in official ag-grid documentation https://www.ag-grid.com/javascript-grid-context-menu/
like image 142
kamil-kubicki Avatar answered Oct 17 '25 18:10

kamil-kubicki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!