reactjsmaterial-uidatagridexport-to-csvmui-datatable

Is there any option available in DataGrid MUI to export columns with renderCell on a complex object?


I am exporting DataGrid @mui/x-data-grid table using CustomToolbar

I have one of the columns as below

        {
            field: 'industry_type',
            headerName: 'Industry',
            renderCell: (params) => {
                const industry = params.row.industry_type;
                return (
                    <>
                        <p>{`${industry.code}- ${industry.value}`} </p>
                    </>
                );
            }
        }

The csv file downloaded from export option gives the value as [object Object]

How do I get the actual value in csv downloaded file? I need help in fixing this. Thanks.


Solution

  • Does valueGetter work for exports?

            {
                field: 'industry_type',
                headerName: 'Industry',
                renderCell: (params) => {
                    const industry = params.row.industry_type;
                    return (
                        <>
                            <p>{`${industry.code}- ${industry.value}`} </p>
                        </>
                    );
                },
                valueGetter: (params) => `${params.row.industry_type.code}- ${params.row.industry_type.value}`,
            }