gridOptions.columnDefs = [
{headerName: "Country", field: "country", rowGroup: true },
{headerName: "Year", field: "year", rowGroup: true },
{headerName: "Gold", field: "gold", aggFunc: 'sum' },
{headerName: "Silver", field: "silver", aggFunc: 'sum' },
{headerName: "Bronze", field: "bronze", aggFunc: 'sum' },
{headerName: "Total", field: "total", aggFunc: 'sum'}
];
其中,'aggFunc'属性指定了使用哪个聚合函数。
function exportToExcel() {
gridOptions.api.exportDataAsExcel({
suppressQuotes: true,
fileName: 'ag-grid-export.xlsx',
allColumns: true,
columnGroups: true,
customHeader: [['Ag-grid Export']],
customFooter: [['End of Report']]
});
}
其中,exportDataAsExcel()是Ag-grid提供的导出数据的功能。您可以使用不同的选项来自定义输出。
function exportToExcel() {
gridOptions.api.exportDataAsExcel({
suppressQuotes: true,
fileName: 'ag-grid-export.xlsx',
allColumns: true,
columnGroups: true,
customHeader: [['Ag-grid Export']],
customFooter: [['End of Report']],
processCellCallback: function(params) {
if (params.column.isRowGroupDisplayed() && params.node.group) {
if (params.column.colId == 'country' || params.column.colId == 'year') {
// 在每个组的开头添加一个空格
params.value = ' ' + params.value;
}
//