Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGridPremium] Fix print export not working with row grouping #12957

Merged
merged 5 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { gridClasses } from '../../../constants/gridClasses';
import { useGridApiMethod } from '../../utils/useGridApiMethod';
import { gridRowsMetaSelector } from '../rows/gridRowsMetaSelector';
import { GRID_ID_AUTOGENERATED } from '../rows/gridRowsUtils';
import { defaultGetRowsToExport, getColumnsToExport } from './utils';
import { getDerivedPaginationModel } from '../pagination/useGridPaginationModel';
import { GridPipeProcessor, useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
Expand Down Expand Up @@ -106,7 +107,15 @@ export const useGridPrintExport = (
const updateGridRowsForPrint = React.useCallback(
(getRowsToExport: NonNullable<GridPrintExportOptions['getRowsToExport']>) => {
const rowsToExportIds = getRowsToExport({ apiRef });
const newRows = rowsToExportIds.map((id) => apiRef.current.getRow(id));

const newRows = rowsToExportIds.reduce<GridValidRowModel[]>((acc, id) => {
const row = apiRef.current.getRow(id);
if (!row[GRID_ID_AUTOGENERATED]) {
acc.push(row);
}
return acc;
}, [] as GridValidRowModel[]);

apiRef.current.setRows(newRows);
},
[apiRef],
Expand Down Expand Up @@ -293,7 +302,9 @@ export const useGridPrintExport = (
previousGridState.current = apiRef.current.exportState();
// It appends that the visibility model is not exported, especially if columnVisibility is not controlled
previousColumnVisibility.current = gridColumnVisibilityModelSelector(apiRef);
previousRows.current = apiRef.current.getSortedRows();
previousRows.current = apiRef.current
.getSortedRows()
.filter((row) => !row[GRID_ID_AUTOGENERATED]);

if (props.pagination) {
const visibleRowCount = gridExpandedRowCountSelector(apiRef);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { createSelector, createSelectorMemoized } from '../../../utils/createSelector';
import { GridSortDirection, GridSortModel } from '../../../models/gridSortModel';
import { GridStateCommunity } from '../../../models/gridStateCommunity';
import { gridRowsLookupSelector } from '../rows/gridRowsSelector';
import { gridRowTreeSelector, gridRowsLookupSelector } from '../rows/gridRowsSelector';
import { GridValidRowModel } from '../../../models/gridRows';
import { GRID_ID_AUTOGENERATED, isAutoGeneratedRow } from '../rows/gridRowsUtils';

/**
* @category Sorting
Expand All @@ -25,8 +27,19 @@ export const gridSortedRowIdsSelector = createSelector(
export const gridSortedRowEntriesSelector = createSelectorMemoized(
gridSortedRowIdsSelector,
gridRowsLookupSelector,
// TODO rows v6: Is this the best approach ?
(sortedIds, idRowsLookup) => sortedIds.map((id) => ({ id, model: idRowsLookup[id] ?? {} })),
gridRowTreeSelector,
(sortedIds, idRowsLookup, rowTree) =>
sortedIds.reduce<GridValidRowModel[]>((acc, id) => {
const model = idRowsLookup[id];
if (model) {
acc.push({ id, model });
}
const rowNode = rowTree[id];
if (isAutoGeneratedRow(rowNode)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To align with

const node = apiRef.current.getRowNode(id);
if (node && isAutoGeneratedRow(node)) {
return { [GRID_ID_AUTOGENERATED]: id };
}

acc.push({ id, model: { [GRID_ID_AUTOGENERATED]: id } });
}
return acc;
}, [] as GridValidRowModel[]),
);

/**
Expand Down
Loading