[MUI] DataGrid CSV Export fileName 설정하기

이경은·2022년 10월 17일
0

⚡ 서론

  • MUI DataGrid에서 CSV Export option을 사용해서 파일을 export 하게 되면, 기본 이름은 {document.title}.csv 로 저장된다.
  • 내가 원하는 이름으로 저장하려면 다른 옵션을 사용해야 함.

🔥 How to

  • GridToolbarExport에 csvOptions에서 fileName을 설정하면 된다.
  • .csv는 자동을 붙여주니 쓰지 않아야 한다.
function CustomToolbar() {
    return (
        <GridToolbarContainer>
            <GridToolbarExport
                csvOptions={{ fileName: 'custom file name' }}
            />
        	...
        </GridToolbarContainer>
    )
}

<DataGrid
    rows={rows}
    columns={columns}
    components={{
        Toolbar: CustomToolbar,
        ...
    }}
		...
/>

참조

https://mui.com/x/api/data-grid/grid-csv-export-options/#properties

profile
Web Developer

0개의 댓글