I am looking at adding footer buttons to my AG Grid and want them to be related to the grid rows i.e. I want them to be either enabled/disabled based on certain row-specific data.
I am not sure if that would require a custom implementation OR if there is some out-of-the-box support within Ag-grid ?
ISSUE
class CustomPinnedRowRenderer {
init(params) {
this.eGui = document.createElement('div');
this.eGui.innerHTML = `<button id='editBtn'>Edit<button> <button id='deleteBtn' disabled>Delete<button>`;
}
After executing the line this.eGui.innerHTML, I somehow get an unnecessary/extra button element, NOT sure why...so the actual innerHTML rendered after I inspect is as below;
<button id="editBtn">Edit</button><button> </button><button id="deleteBtn" disabled="">Delete</button><button></button>
There's a few ways of achieving this:
The key here is the following:
<AgGridReact
// ...
onRowSelected={(params) => {
params.api.redrawRows({
rowNodes: [params.api.getPinnedBottomRow(0)],
});
}}
isFullWidthCell={(rowNode) => rowNode.rowPinned === 'bottom'}
fullWidthCellRenderer={CustomPinnedRowRenderer}
pinnedBottomRowData={[{}]}
></AgGridReact>
onRowSelected, so that the logic to disable the button can be recomputedconst CustomPinnedRowRenderer = memo((props) => {
const selectedNodes = props.api.getSelectedNodes();
const isFirstRowSelected =
selectedNodes.filter((node) => node.rowIndex === 0).length > 0;
return (
<button disabled={isFirstRowSelected}>
enabled only if first row is selected
</button>
);
});
See this implemented in the following Plunkr