-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DataGrid] Add support for
getRowsToExport
option to print export (#…
…10084) Co-authored-by: Andrew Cherniavskyi <[email protected]>
- Loading branch information
1 parent
52b7efa
commit 82d44ea
Showing
13 changed files
with
207 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as React from 'react'; | ||
import { useDemoData } from '@mui/x-data-grid-generator'; | ||
import { | ||
DataGrid, | ||
GridToolbar, | ||
gridFilteredSortedRowIdsSelector, | ||
selectedGridRowsSelector, | ||
} from '@mui/x-data-grid'; | ||
|
||
const getSelectedRowsToExport = ({ apiRef }) => { | ||
const selectedRowIds = selectedGridRowsSelector(apiRef); | ||
if (selectedRowIds.size > 0) { | ||
return Array.from(selectedRowIds.keys()); | ||
} | ||
|
||
return gridFilteredSortedRowIdsSelector(apiRef); | ||
}; | ||
|
||
export default function PrintExportSelectedRows() { | ||
const { data, loading } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 10, | ||
maxColumns: 6, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 300, width: '100%' }}> | ||
<DataGrid | ||
{...data} | ||
checkboxSelection | ||
loading={loading} | ||
slots={{ toolbar: GridToolbar }} | ||
slotProps={{ | ||
toolbar: { printOptions: { getRowsToExport: getSelectedRowsToExport } }, | ||
}} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as React from 'react'; | ||
import { useDemoData } from '@mui/x-data-grid-generator'; | ||
import { | ||
DataGrid, | ||
GridToolbar, | ||
GridPrintGetRowsToExportParams, | ||
gridFilteredSortedRowIdsSelector, | ||
selectedGridRowsSelector, | ||
GridRowId, | ||
} from '@mui/x-data-grid'; | ||
|
||
const getSelectedRowsToExport = ({ | ||
apiRef, | ||
}: GridPrintGetRowsToExportParams): GridRowId[] => { | ||
const selectedRowIds = selectedGridRowsSelector(apiRef); | ||
if (selectedRowIds.size > 0) { | ||
return Array.from(selectedRowIds.keys()); | ||
} | ||
|
||
return gridFilteredSortedRowIdsSelector(apiRef); | ||
}; | ||
|
||
export default function PrintExportSelectedRows() { | ||
const { data, loading } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 10, | ||
maxColumns: 6, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 300, width: '100%' }}> | ||
<DataGrid | ||
{...data} | ||
checkboxSelection | ||
loading={loading} | ||
slots={{ toolbar: GridToolbar }} | ||
slotProps={{ | ||
toolbar: { printOptions: { getRowsToExport: getSelectedRowsToExport } }, | ||
}} | ||
/> | ||
</div> | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
docs/data/data-grid/export/PrintExportSelectedRows.tsx.preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<DataGrid | ||
{...data} | ||
checkboxSelection | ||
loading={loading} | ||
slots={{ toolbar: GridToolbar }} | ||
slotProps={{ | ||
toolbar: { printOptions: { getRowsToExport: getSelectedRowsToExport } }, | ||
}} | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.