Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to hide column in export

How to hide the select all(checkbox) column in excel or csv export.

{
    checkboxSelection: true,
    suppressMenu: true,
    suppressSorting: true,
    suppressFilter: true,
    width: 30,
    pinned: true,
    suppressExcelExport :true,
    headerCellRenderer: this.selectAllRenderer
},
like image 906
Satendra Jindal Avatar asked Jan 24 '26 08:01

Satendra Jindal


2 Answers

below code will solve your problem

var columnsForExport=[];
var allColumns=gridOption.columnApi.getAllColumns();

allColumns.forEach((element:any) => {
    if(element.colId!="#"){
        columnsForExport.push(element.colId)
    }
});
like image 118
Nishant Kumar Avatar answered Jan 25 '26 21:01

Nishant Kumar


As for now, the suppressExcelExport: true property works only for the entire grid, not the columns!

However there is a nice workaround which will enable any custom column property (e.g. suppressExcelExport) to act like a real working property as you asked.

All you need is calling this function on a button click or add context menu item:

function exportActiveColumns() {
    let allColumns = gridOptions.columnApi.getAllColumns();
    let exportColumns = allColumns .filter(col => !col.userProvidedColDef.suppressExcelExport);
    gridOptions.api.exportDataAsExcel({
        columnKeys: exportColumns,
    });
}

Make sure suppressExcelExport is false for the grid, otherwise there will be no result after calling exportDataAsExcel api.

Exact same thing works for CSV.

like image 33
Rafe Avatar answered Jan 25 '26 22:01

Rafe