I have been working on creating an independent component using ag-grid. The column definitions are passed to this component from my application as input properties, defined like this:
interface ColumnDef {
field: string;
headerName: string;
}
@Input() colDef: ColumnDef[];
Currently, I am able to pass different sets of columns from the host application to the common component with unique IDs.
However, now I have a new requirement where I need to dynamically define the row data type for ag-grid inside the common component as well.
For example, if I pass column definitions like:
[{field: 'colA', headerName: 'Col A'},
{field: 'colB', headerName: 'Col B'}]
The component should generate a row data type dynamically as follows:
interface rowData {
colA: string;
colB: string;
}
Similarly, if I pass more columns like:
[{field: 'colA', headerName: 'Col A'},
{field: 'colB', headerName: 'Col B'},
{field: 'colC', headerName: 'Col C'}]
The row data type should be created accordingly:
interface rowData {
colA: string;
colB: string;
colC: string;
}
This dynamic definition would allow me to use the interface for typing the row data effectively. Is there a way to achieve this functionality?
Thank you for your assistance.