@AIM_Rhys
You can manage this by transforming the object you'll be receiving and grouping the objects into child objects if there are more then 1 record for the unique identifier (TripID in your case) available. Then enable expandable rows, add a table (or whatever you'd like to display) to the expandable row component and reference the data to it using {{currentSourceRow.trips}} in my case.
See attached the screenshot and the JS function to group by. You'll probably need to update it to your own columns, but transforming the data should work.
function groupTrips(trips) {
const tripMap = trips.reduce((acc, trip) => {
if (!acc[trip.TripCode]) {
acc[trip.TripCode] = [];
}
acc[trip.TripCode].push(trip);
return acc;
}, {});
const groupedTrips = Object.keys(tripMap).map(tripCode => {
const tripEntries = tripMap[tripCode];
if (tripEntries.length > 1) {
// If multiple trips share the same TripCode, create a parent object
return {
TripCode: tripCode,
isGroup: true,
totalParticipants: tripEntries.reduce((sum, t) => sum + (t.NumberOfParticipants || 0), 0),
trips: tripEntries
};
} else {
// Single trip remains as is
return tripEntries[0];
}
});
return groupedTrips;
}
// Mock Data Example
const tripsData = [
{ TripCode: "25Y0322PR", Name: "Victory Outreach", MissionCoordinator: "Karla", NumberOfParticipants: 10 },
{ TripCode: "25Y0322PR", Name: "Fred Church", MissionCoordinator: "Karla", NumberOfParticipants: 9 },
{ TripCode: "25Y0322BIC", Name: "Lakeside Baptist", MissionCoordinator: "Keith", NumberOfParticipants: 8 },
{ TripCode: "25Y0322NC", Name: "Carolina Church", MissionCoordinator: "Savanna", NumberOfParticipants: 1 },
{ TripCode: "25Y0329CH", Name: "Maranatha", MissionCoordinator: "Matt", NumberOfParticipants: 9 },
{ TripCode: "25E0405NC", Name: "Team Ritter", MissionCoordinator: "Savanna", NumberOfParticipants: 11 },
{ TripCode: "25E0405NC", Name: "Johnson Group", MissionCoordinator: "Savanna", NumberOfParticipants: 3 },
{ TripCode: "25F0412NC", Name: "Wallace Family", MissionCoordinator: "Brett", NumberOfParticipants: 16 },
{ TripCode: "25E0426NC", Name: "Coastal Church", MissionCoordinator: "Todd", NumberOfParticipants: 10 },
{ TripCode: "25E0426NC", Name: "Gunston EPC", MissionCoordinator: "Stephen", NumberOfParticipants: 15 },
{ TripCode: "25E0426NC", Name: "Grace Bible", MissionCoordinator: "Art", NumberOfParticipants: 10 }
];
return(groupTrips(tripsData));
Make sure to change the mockdata and reference it to your source.