I want implement multi row edit based on the selected rows, but unfortunatlty I am unable to find any example on ag-grid documentation. Here is Plunker link where I have Multi-line checkboxes on Row groups whenever I selected the rows the selected rows become editable but the issues When II focus/edit on any one of the cell all of the other selected editable rows become normal. Is ag-grid provide this feature or is it possible in ag-grid? Thanks!
import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ClientSideRowModelModule } from '@ag-grid-community/client-side-row-model';
import { RowGroupingModule } from '@ag-grid-enterprise/row-grouping';
import { MenuModule } from '@ag-grid-enterprise/menu';
import { ColumnsToolPanelModule } from '@ag-grid-enterprise/column-tool-panel';
import '@ag-grid-community/core/dist/styles/ag-grid.css';
import '@ag-grid-community/core/dist/styles/ag-theme-alpine.css';
@Component({
selector: 'my-app',
template: `<ag-grid-angular
#agGrid
style="width: 100%; height: 100%;"
id="myGrid"
class="ag-theme-alpine"
[modules]="modules"
[columnDefs]="columnDefs"
[defaultColDef]="defaultColDef"
[autoGroupColumnDef]="autoGroupColumnDef"
[rowSelection]="rowSelection"
(selectionChanged)="gridRowSelectionChanged($event)"
[groupSelectsChildren]="true"
[suppressRowClickSelection]="true"
[suppressAggFuncInHeader]="true"
[rowData]="rowData"
(gridReady)="onGridReady($event)"
></ag-grid-angular>`,
})
export class AppComponent {
private gridApi;
private gridColumnApi;
public modules: Module[] = [
ClientSideRowModelModule,
RowGroupingModule,
MenuModule,
ColumnsToolPanelModule,
];
private columnDefs;
private defaultColDef;
private autoGroupColumnDef;
private rowSelection;
private rowData: [];
constructor(private http: HttpClient) {
this.columnDefs = [
{
field: 'country',
rowGroup: true,
hide: true,
},
{
field: 'gold',
aggFunc: 'sum',
editable: true
},
{
field: 'silver',
aggFunc: 'sum',
editable: true
},
{
field: 'bronze',
aggFunc: 'sum',
editable: true
},
{
field: 'age',
minWidth: 120,
checkboxSelection: true,
aggFunc: 'sum',
},
{
field: 'year',
maxWidth: 120,
},
{
field: 'date',
minWidth: 150,
},
];
this.defaultColDef = {
flex: 1,
minWidth: 100,
};
this.autoGroupColumnDef = {
headerName: 'Athlete',
field: 'athlete',
minWidth: 250,
cellRenderer: 'agGroupCellRenderer',
cellRendererParams: { checkbox: true },
};
this.rowSelection = 'multiple';
}
onGridReady(params) {
this.gridApi = params.api;
this.gridColumnApi = params.columnApi;
this.http
.get('https://www.ag-grid.com/example-assets/olympic-winners.json')
.subscribe((data) => {
this.rowData = data;
});
}
gridRowSelectionChanged(params) {
const selectedNodes = params.api.getSelectedNodes();
selectedNodes.forEach(node => {
this.gridApi.startEditingCell({
rowIndex: node.rowIndex,
colKey: 'gold',
});
});
}
}
You can change selected rows data with cellValueChanged event. for example to make the value of column a same in selected rows ,you only need to edit 1 cell
https://www.ag-grid.com/angular-grid/cell-editing/#event-cell-value-changed
You can prevent deselection using grid option suppressRowClickSelection: true
Have a look at my example below https://plnkr.co/edit/1aQyW0NSpjYYPNE2?preview
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.