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

2

5

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.

Dees answered 8/4, 2022 at 4:37 Comment(0)
R
6

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}`,
        }
Red answered 8/4, 2022 at 5:17 Comment(1)
Confirmed, valueGetter works for exports. In MUI4 v at least though, note that valueGetter supercedes the renderCell, so you would lose the <p> breaks in your render - which in this example you probably don't need anyway, but just a heads up.Barbee
N
0

According to the MUI data grid docs here, you can provide the valueFormatter

{
        field: 'industry_type',
        headerName: 'Industry',
        renderCell: (params) => {
            const industry = params.row.industry_type;
            return (
                <>
                    <p>{`${industry.code}- ${industry.value}`} </p>
                </>
            );
        },
        valueFormatter: ({ value }) => `${value.industry_type.code}- ${value.industry_type.value}`,
    }
Notable answered 2/11, 2023 at 0:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.