I have some problems with making custom cell renderer with menu for edit all row in one click.
First of all I want to render menu icon, on user click the dropdown shows and I select 'edit' option (don't bother about remove option). Ok so I have visual aspect of cell in the definiton of the column:
columnsDefinition.push({
headerName: '',
cellRendererFramework: EditRendererComponent,
cellRendererParams: {
// params will be here
}
});
Ok lets go to the next step. I need some extra params, I know how to pass static params of component, but I also need data from the row where my cell is rendered - I don't know how to pass it to the custom renderer component.
This is my EditRendererComponent:
export class EditRendererComponent implements ICellRendererAngularComp {
isEditing = false;
params: any;
agInit(params: ICellRendererParams) {
this.params = params;
}
refresh(params: any): boolean {
return false;
}
editMode() {
// we need to loop thru all rows, find the column with the renderer, and 'cancel the edit mode'.
// otherwise, we will end up with rows that has SAVE buttons appearing but not in edit mode
const renderersInOtherRows = this.params.api.getCellRendererInstances(this.params);
if( renderersInOtherRows && renderersInOtherRows.length > 0 ) {
for(const wrapper of renderersInOtherRows) {
if (wrapper.getFrameworkComponentInstance() instanceof EditRendererComponent ) {
const foundRenderer = wrapper.getFrameworkComponentInstance() as EditRendererComponent;
if( foundRenderer.isEditing ) {
foundRenderer.onCancel();
}
}
}
}
this.isEditing = true;
this.params.api.startEditingCell( { rowIndex: this.params.node.rowIndex, colKey: 'some-col-field-name'});
}
onCancel() {
this.isEditing = false;
// restore previous data or reload
}
onSave() {
this.isEditing = false;
// do your saving logic
}
}
Summary, I need help with:
1) Pass record data to the renderer component
2) editMode()
method doesn't work at all, any ideas how it should be resolved to make all cells editable (only when columns def editable
is set to true)?