我努力固定一个小组专栏,我想与全世界分享我的解决方案。请参阅autoGroupColumnDef部分。希望这有帮助!
var columnDefs = [
{ headerName: "Console", field: "console", width: 140, rowGroup: true},
{ headerName: "Alarm Type", field: "AlarmType", width: 20, pivot: true },
{ headerName: "Total", field: "Total", width: 55, aggFunc: 'sum'},
{ headerName: "%", field: "Percentage", width: 50, aggFunc: 'sum', cellRenderer: roundNumber },
{ headerName: "IP", field: "InProgress", width: 45, aggFunc: 'sum', cellRenderer: roundNumber }
];
var gridOptions = {
groupMultiAutoColumn: true,
groupDefaultExpanded: -1,
suppressAggFuncInHeader: true,
groupSuppressBlankHeader: true,
pivotMode: true,
columnDefs: columnDefs,
enableRangeSelection: true,
toolPanelSuppressRowGroups: true,
toolPanelSuppressPivotMode: true,
toolPanelSuppressPivots: true,
toolPanelSuppressValues: true,
autoGroupColumnDef: {
headerName: 'Consoles',//custom header name for group
pinned: 'left',//force pinned left. Does not work in columnDef
cellRendererParams: {
suppressCount: true,//remove number in Group Column
}
}
};
答案 0 :(得分:0)
要实现预期用途,请使用以下删除pivotMode的选项:true,这会在将列固定在左侧时引起问题
工作解决方案供参考
var columnDefs = [
{ headerName: "Console", field: "console", width: 140, rowGroup: true},
{ headerName: "Alarm Type", field: "AlarmType", width: 55, pivot: true },
{ headerName: "Total", field: "Total", width: 55, aggFunc: 'sum'},
{ headerName: "%", field: "Percentage", width: 50, aggFunc: 'sum'},
{ headerName: "IP", field: "InProgress", width: 45, aggFunc: 'sum'}
];
var gridOptions = {
groupMultiAutoColumn: true,
groupDefaultExpanded: -1,
suppressAggFuncInHeader: true,
groupSuppressBlankHeader: true,
columnDefs: columnDefs,
enableRangeSelection: true,
toolPanelSuppressRowGroups: true,
toolPanelSuppressPivotMode: true,
toolPanelSuppressValues: true,
autoGroupColumnDef: {
headerName: 'Consoles',//custom header name for group
pinned: 'left',//force pinned left. Does not work in columnDef
cellRendererParams: {
suppressCount: true,//remove number in Group Column
}
}
};
// setup the grid after the page has finished loading
document.addEventListener('DOMContentLoaded', function() {
var gridDiv = document.querySelector('#myGrid');
new agGrid.Grid(gridDiv, gridOptions);
var data = [
{'console': 1, 'AlarmType': 'A', 'Total': 200, 'Percentage': 20, 'InProgress': 123456},
{'console': 1, 'AlarmType': 'A', 'Total': 200, 'Percentage': 20, 'InProgress': 123456}
];
gridOptions.api.setRowData(data);
});
<!DOCTYPE html>
<html lang="en">
<head>
<script> var __basePath = ''; </script>
<style media="only screen">
html, body {
height: 50%;
width: 60%;
margin: 0;
box-sizing: border-box;
-webkit-overflow-scrolling: touch;
}
html {
position: absolute;
top: 0;
left: 0;
padding: 0;
overflow: auto;
}
body {
padding: 1rem;
overflow: auto;
}
</style>
<script src='https://unpkg.com/@ag-grid-community/all-modules@22.1.1/dist/ag-grid-community.min.js'></script></head>
<body>
<div id="myGrid" style="height: 100%;" class="ag-theme-balham"></div>
<script src="main.js"></script>
</body>
</html>