I am trying to use ag grid to show data in my component. I am making an API call and then dynamically extracting the data column name from response and passing this information to the child component to display. But it not showing the data.
When I don’t use dynamic behaviour and get the static configuration from variable it is working.
Static Column Config =>
export let DETIALCONFIG= {
columnDefs: [
{
headerName: 'VT Name',
field: 'vtName',
hide: false,
minWidth: 235,
serverFlag: true,
tooltipFields: 'veName'
},
{
headerName: 'Key',
field: 'KEY',
hide: false,
serverFlag: true,
},
{
headerName: 'ID',
field: 'ID',
hide: true,
serverFlag: true,
},
{
headerName: 'APP Name',
field: 'APP_NAME',
hide: true,
minWidth: 140,
serverFlag: true,
},
{
headerName: 'Status ',
field: 'Status',
hide: true,
minWidth: 200,
serverFlag: true,
},
{
headerName: 'Version',
field: 'VERSION',
hide: true,
minWidth: 235,
serverFlag: true,
},
{
headerName: 'Details',
field: 'DETAILS',
hide: true,
minWidth: 235,
serverFlag: true,
},
{
headerName: 'Json',
field: 'JSON',
hide: true,
minWidth: 235,
serverFlag: true,
},
],
gridOptions: {
domLayout: 'autoHeight',
pagination: false,
paginationPageSize: 6,
rowSelection: 'multiple',
enableColResize: true,
enableSorting: true,
enableFilter: true,
suppressPropertyNamesCheck: true,
enableBrowserTooltips: true,
suppressAutoSize: true
}
}
Dynamic Logic
private run = async (veName: string) => {
let response: any
try {
response = await apiCall(veName, [], true)
this.veTableData = [...response.data]
const keys = Object.keys(this.veTableData[0])
this.columnConfig = this.veDetailsGridConfig
this.columnConfig.columnDefs.map((item: any) => {
if(keys.includes(item.field)) {
item.hide = false
return item
}
})
console.log(this.columnConfig)
this.tableHeader = veName.toUpperCase()
} catch (err) {
this.veTableData = []
this.columnConfig = this.veDetailsGridConfig
}
with dynamic logic when I try to display this columnConfig in templete inside gripOptions property another columnDefs is getting added every time. It is not happening with static behaviour, and I suppose this is the issue. Can you guys please looks what I am doing wrong here. Thanks