Hiding of row count in ag grid aggregation / row grouping - ag-grid

Is there a way to hide the row count in the aggregated rows in ag-grid?
I couldn't find any specific configuration to hide the row count appearning beside the aggregated cell.

You can use suppressCount within cellRendererParams
cellRendererParams: {
suppressCount: true, // turn off the row count
}

The last two answers do not seem to work in v25 of the ag-Grid.
See this page: https://www.ag-grid.com/javascript-grid/grouping/
The solution for me is to use the autoGroupColumnDef like the following:
autoGroupColumnDef: {
cellRendererParams: {
suppressCount: true
}
}

When using gridOptions.groupUseEntireRow = true you can set it with
gridOptions.groupRowRendererParams = {
suppressCount: true
};

Related

Simple way to programatically remove all grouping and filtering

When the grid loads there is no grouping/filtering applied. I want to be able to remove any grouping/filtering which the user has applied manually i.e. get the grid format back to its original state.
You can do this with help of gridOptions of ag-grid. Try to do the below changes..
Initialize gridOptions if not yet along with column definitions and set the grid options in ag-grid.
Component.ts
this.gridOptions = {
defaultColDef: {
editable: true,
resizable: true,
filter: true
},
columnDefs: this.columnDefs,
rowData: this.rowData
};
clear the filters with like below
...
gridOptions.api.setFilterModel(null);
gridOptions.api.onFilterChanged();
...
component.html
<ag-grid .. [gridOptions] = "gridOptions" ..> </ag-grid>
You can see more about this in the ag-grid documentation.
you can define a function to reset everything
function ResetGrid(){
//clear filters
gridOptions.api.setFilterModel(null);
//notify grid to implement the changes
gridOptions.api.onFilterChanged();
//remove all pivots
gridOptions.columnApi.setPivotColumns([]);
// disable pivot mode
gridOptions.columnApi.setPivotMode(false);
//reset all grouping
gridOptions.api.setColumnDefs(columnDefs);
//where columDefs is the object you used while creating grid first time.
}
the above method does what you want but more sophisticated way to do this will be saving column state(it may be at iniital stage or later after certain operation).
function saveState() {
window.colState = gridOptions.columnApi.getColumnState();
window.groupState = gridOptions.columnApi.getColumnGroupState();
window.sortState = gridOptions.api.getSortModel();
window.filterState = gridOptions.api.getFilterModel();
console.log('column state saved');
}
function restoreState() {
if (!window.colState) {
console.log('no columns state to restore by, you must save state first');
return;
}
gridOptions.columnApi.setColumnState(window.colState);
gridOptions.columnApi.setColumnGroupState(window.groupState);
gridOptions.api.setSortModel(window.sortState);
gridOptions.api.setFilterModel(window.filterState);
console.log('column state restored');
}
function resetState() {
gridOptions.columnApi.resetColumnState();
gridOptions.columnApi.resetColumnGroupState();
gridOptions.api.setSortModel(null);
gridOptions.api.setFilterModel(null);
console.log('column state reset');
}
here is a demo
Here is how you can remove all filters and row groups. For more info, see GridApi.
gridApi.setFilterModel(null);
gridApi.setRowGroupColumns([]);
gridApi.onFilterChanged();
Live Example

ag-Grid Master / Detail - Row Selection

Goals
I am trying to add row selection functionality which is connected between the master grid and detail grid.
When a checkbox on a master grid row is selected, I want to select all the checkboxes in the associated detail grid.
When a checkbox on a master grid row is deselected, I want to deselect all the checkboxes in the associated detail grid.
When only partial checkboxes inside of a detail grid are selected, I want the master grid row to show a partial selection icon in the checkbox.
I want to keep count of how many items were selected in all of the detail grids
Questions/Problems
All of this functionality already exists for Groups, but I cannot get it to work for Master/Detail. I've tried adding in the line that I believe should add this for Groups cellRendererParams: {checkbox: true}, but that does nothing for the detail grid.
I've also tried implementing the functionality myself, but I hit a couple of roadblocks.
I don't know how to set the partial-checkbox icon manually or if that's even possible.
I implemented the onSelectionChanged event handler for the detail grid, but inside of the function it looks like I can't access the Angular component context to update the count of selected items. Not sure how to pass in the context this.
Code that I have working so far:
When a checkbox on a master grid is selected/deselected, the checkboxes in the associated detail grid are all selected/deselected.
public onMasterRowSelected() {
this.gridOptions.api.forEachNode(masterRowNode => {
if(masterRowNode.isSelected()) {
this.gridOptions.api.getDetailGridInfo(`detail_${masterRowNode.id}`).api.selectAll();
} else {
this.gridOptions.api.getDetailGridInfo(`detail_${masterRowNode.id}`).api.forEachNode(detailRowNode => detailRowNode.setSelected(false));
}
});
}
Added the onSelectionChanged() event listener for the detail grid.
constructor() {
this.gridOptions = {
...
detailCellRendererParams: {
getDetailRowData: function(params) {
params.successCallback(params.data.items); // Defines where to find the detail fields out of the rowData object
},
detailGridOptions: {
rowSelection: 'multiple',
defaultColDef: {
sortable: true
},
getRowNodeId: function (rowData) {
return rowData.id; // detail items are indexed by id field
},
onSelectionChanged: function (params) {
console.log(this); // I expected this to print out my Angular component object, but instead it prints out this.gridOptions.detailCellRendererParams.detailGridOptions
console.log("TEST"); // I know that this function is successfully being called because this line is printed
this.selectedItems = 0;
params.api.forEachNode(detailRowNode => {
if(detailRowNode.isSelected()) {
this.selectedObs++; // I believe that this would work if I had access to the correct "this" context
}
});
},
columnDefs: [
{headerName: 'Column 1', field: 'column1', checkboxSelection: true},
{headerName: 'Column 2', field: 'column2'},
]
}
}
};
}
Here is an Angular example where you can push the parent component as a reference to the detail grid and set it as its context. Doing this allows you to register a component method as a callback for the detail grid's onRowSelected method.
https://stackblitz.com/edit/ag-grid-detailrow-selectcallback?file=src/app/app.component.ts
Move the onSelectionChanged(params) function to the same level as the detailCellRendererParams object.
internalOnSelectionChanged(params)
{
this.detailGridApi = params.api;
this.detailGridColumnApi = params.columnApi;
console.log(this);
}
Then, on the onSelectionChanged, do this:
onSelectionChanged: this.internalOnSelectionChanged.bind(this);
This solved my issues that were very similar to yours.

Ag-grid React: How to disable row group collapse

I have an ag-grid where rows are grouped by first column. The group are expanded by default. I want to disable group collapse on click.
colDefs = [{
field: 'colA',
rowGroup: true,
hide: true
}, {
field: 'colB'
},
...
];
gridOptions = {
groupDefaultExpanded: -1,
...
}
How do i prevent from collapsing the group open by default
I guess the colB has a showRowGroup: 'colA' and a cellRenderer: 'agGroupCellRenderer'.
You can remove the cellRenderer from it and it will display the group title as a simple string without showing the collapse icon and without the collapse abililty too.
I managed to do that by adding the following css:.ag-group-expanded {pointer-events: none;}
I also set to true suppressDoubleClickExpand and suppressEnterExpand so there is no way to collapse the rows.

How to subscribe for a filter changed event in ag grid

I have a problem in which i need to display the number of rows filtered in ag grid at run time.
How can I subscribe for a filter changed event in ag grid(javascript version )?
Ag grid has callbacks 'onFilterChanged' & 'onFilterModified'
var gridOptions = {
columnDefs: columnDefs,
rowData: null,
enableFilter: true,
onFilterChanged: function() {console.log('onFilterChanged');},
onFilterModified: function() {console.log('onFilterModified');}
};
You can find more details here https://www.ag-grid.com/javascript-grid-filtering/
I was searching for the way how to subscribe to the 'onFilterChange' event.
I need to track the number of rows on each filter change.
filteredRows is the field to be shown with number of filtered rows.
this.gridOptions.api.eventService.addEventListener('filterChanged', (e) => {
this.filteredRows = e.api.paginationGetRowCount();
})
For me, it helped to add a method to the filterChanged listener:
<ag-grid-angular
...
[rowData]="rowData"
(filterChanged)="onFilterChanged($event)"
>
</ag-grid-angular>
Then I created a function that uses the params api to get the current displayed rows:
onFilterChanged(params: GridOptions): void {
console.log(this.numberOfRows = params.api?.getDisplayedRowCount());
}
I hope this helps anybody too.

Ag-grid pivot group count

I'm using Ag-grid 16.0 with Angular 5.
I want to hide count of pivot group.
rowGroup: true,
cellRenderer:'agGroupCellRenderer',
cellRendererParams: {
suppressCount: false, // turn off the row count
}
suppressCount: false doesn't work for me.
How could I delete the count of pivot group?
Thank you for helping me in advance.
#pivot group count image
Should be
cellRendererParams: {
suppressCount: true
}