Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
MBilalShafi committed Dec 23, 2024
1 parent 20dc5f7 commit 38a0a6b
Showing 1 changed file with 40 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,13 @@ const getAggregationCellValue = ({
field,
aggregationFunction,
aggregationRowsScope,
isDataSource,
}: {
apiRef: React.MutableRefObject<GridPrivateApiPremium>;
groupId: GridRowId;
field: string;
aggregationFunction: GridAggregationFunction | GridAggregationFunctionDataSource;
aggregationFunction: GridAggregationFunction;
aggregationRowsScope: DataGridPremiumProcessedProps['aggregationRowsScope'];
isDataSource: boolean;
}) => {
if (isDataSource) {
return apiRef.current.resolveGroupAggregation(groupId, field);
}

const clientSideAggregationFunction = aggregationFunction as GridAggregationFunction;

const filteredRowsLookup = gridFilteredRowsLookupSelector(apiRef);
const rowIds: GridRowId[] = apiRef.current.getRowGroupChildren({ groupId });

Expand All @@ -62,37 +54,60 @@ const getAggregationCellValue = ({
return;
}

if (typeof clientSideAggregationFunction.getCellValue === 'function') {
if (typeof aggregationFunction.getCellValue === 'function') {
const row = apiRef.current.getRow(rowId);
values.push(clientSideAggregationFunction.getCellValue({ row }));
values.push(aggregationFunction.getCellValue({ row }));
} else {
values.push(apiRef.current.getCellValue(rowId, field));
}
});

return clientSideAggregationFunction.apply({
return aggregationFunction.apply({
values,
groupId,
field, // Added per user request in https://github.com/mui/mui-x/issues/6995#issuecomment-1327423455
});
};

const getGroupAggregatedValueDataSource = ({
groupId,
apiRef,
aggregatedFields,
position,
}: {
groupId: GridRowId;
apiRef: React.MutableRefObject<GridPrivateApiPremium>;
aggregatedFields: string[];
position: GridAggregationPosition;
}) => {
const groupAggregationLookup: GridAggregationLookup[GridRowId] = {};

for (let j = 0; j < aggregatedFields.length; j += 1) {
const aggregatedField = aggregatedFields[j];

groupAggregationLookup[aggregatedField] = {
position,
value: apiRef.current.resolveGroupAggregation(groupId, aggregatedField),
};
}

return groupAggregationLookup;
};

const getGroupAggregatedValue = ({
groupId,
apiRef,
aggregationRowsScope,
aggregatedFields,
aggregationRules,
position,
isDataSource,
}: {
groupId: GridRowId;
apiRef: React.MutableRefObject<GridPrivateApiPremium>;
aggregationRowsScope: DataGridPremiumProcessedProps['aggregationRowsScope'];
aggregatedFields: string[];
aggregationRules: GridAggregationRules;
position: GridAggregationPosition;
isDataSource: boolean;
}) => {
const groupAggregationLookup: GridAggregationLookup[GridRowId] = {};

Expand All @@ -106,9 +121,8 @@ const getGroupAggregatedValue = ({
apiRef,
groupId,
field: aggregatedField,
aggregationFunction: columnAggregationRules.aggregationFunction,
aggregationFunction: columnAggregationRules.aggregationFunction as GridAggregationFunction,
aggregationRowsScope,
isDataSource,
}),
};
}
Expand Down Expand Up @@ -155,19 +169,24 @@ export const createAggregationLookup = ({
createGroupAggregationLookup(childNode);
}
}
const position = getAggregationPosition(groupNode);

const hasAggregableChildren = groupNode.children.length;
if (hasAggregableChildren || isDataSource) {
const position = getAggregationPosition(groupNode);
if (position != null) {
if (position != null) {
if (isDataSource) {
aggregationLookup[groupNode.id] = getGroupAggregatedValueDataSource({
groupId: groupNode.id,
apiRef,
aggregatedFields,
position,
});
} else if (groupNode.children.length) {
aggregationLookup[groupNode.id] = getGroupAggregatedValue({
groupId: groupNode.id,
apiRef,
aggregatedFields,
aggregationRowsScope,
aggregationRules,
position,
isDataSource,
});
}
}
Expand Down

0 comments on commit 38a0a6b

Please sign in to comment.