Search code examples
reactjsag-grid

AG Data Grid - How to handle capitalized fields returned by remote site?


I am using React - AG Grid. From remote site, I am getting columns like Name, Type - Capitalized. However, the ColumnDefs needs all lowercase fields in useState, else the table does not show the values fetched from the remote site. How to handle? ...

  const [columnDefs] = useState([
    {field: 'name'}, {field: 'type'} // remote site gives Name, Type
  ]);

Solution

  • You can use the headerName property in columndef. you can refer Accessing Row Data Values

    here is an example code:

    const [columnDefs, setColumnDefs] = useState([
    { headerName: 'name', field: 'Name'},
    { headerName: 'type', field: 'Type'},
    ]);