I'd like to add a "New Payment" button above the Detail grid within the Master Rows. Please feel free to share any tips to enhance the efficiency and reduce potential errors in my component. Here's my current component:
function CreditorsViewer() {
const gridRef = useRef<AgGridReact | null>(null);
const defaultColDef = useMemo( () => ({
sortable: true,
filter: true,
enableRowGroup: true
}), [])
const detailCellRendererParams = useMemo(() => {
return {
detailGridOptions: {
columnDefs: [
{ field: 'amount' },
{ field: 'type' },
{ field: 'year' },
{ field: 'month'},
{ field: 'date' },
],
defaultColDef: {
flex: 1,
sortable: true,
filter: true,
enableRowGroup: true
},
rowSelection: "multiple",
rowGroupPanelShow:"always",
alwaysShowHorizontalScroll: true,
alwaysShowVerticalScroll: true,
},
getDetailRowData: (params: GetDetailRowDataParams) => {
params.successCallback(params.data.payments)
},
};
}, []);
const columnsDefs =[
{ field: "client", cellRenderer: 'agGroupCellRenderer'},
{ field: "contact" },
{ field: "debt", valueFormatter: valueFormatterToDH },
{ field: "pending", valueFormatter: valueFormatterToDH},
{field: "year"},
{field: "date"},
{ field: "transactions" },
];
const cellClickedListener = useCallback((e: { value: any }) => {
console.log('cellClicked', e.value);
}, []);
return (
<div className="h-full container ag-theme-material">
<AgGridReact
defaultColDef={defaultColDef}
masterDetail={true}
detailRowHeight={300}
detailCellRendererParams={detailCellRendererParams}
ref={gridRef}
rowGroupPanelShow="always"
enableRangeSelection={true}
enableCharts={true}
animateRows={true}
rowSelection="multiple"
domLayout="autoHeight"
alwaysShowHorizontalScroll={true}
alwaysShowVerticalScroll={true}
rowData={rowData}
columnDefs={columnsDefs}
onCellClicked={cellClickedListener}
/>
</div>
);
}
I've made an attempt to create a custom detail cell renderer, but I didn't succeed due to my current skillset, and I found the documentation article related to this topic a bit challenging to grasp .
Actually, it's not a big deal.
First add your custom detail cell renderer component
detailCellRenderer.jsx
Here's our styles
We import our component and use it like that
This is a quick forked answer to help you. Please get rid of the parts you do not need.
Here's the working plunker: https://plnkr.co/edit/OXRHpR4tca8DvtgA?preview