I'm attempting to group items in a DetailsList using Fluent UI controls. The example they give is this for the grouping:
const groups = [
{ key: 'groupred0', name: 'Color: "red"', startIndex: 0, count: 2, level: 0 },
{ key: 'groupgreen2', name: 'Color: "green"', startIndex: 2, count: 0, level: 0 },
{ key: 'groupblue2', name: 'Color: "blue"', startIndex: 0, count: 3, level: 0 },
];
I have a list of items. Each items has an InitialAssessment number. Multiple items can have the same InitialAssessment number. This is how I want it grouped.
e.g:
The red boxes demonstrate how I want it grouped by Initial Assessment.
This is what I've tried so far:
const [initialAssessments, setInitialAssessments] = useState([]);
const [theGroups, setTheGroups] = useState([]);
///
const getInitialAssessments = React.useCallback(() => {
const result = [];
const map = new Map();
for (const item of assessments) {
if (!map.has(item.InitialAssessment)) {
map.set(item.InitialAssessment, true);
result.push({
InitialAssessment: item.InitialAssessment,
name: item.Business,
});
}
}
setInitialAssessments(result);
let arr1 = assessments;
let arr2 = arr1.map(v => ({
key: v.Id,
name: v.InitialAssessment,
startIndex: 0,
count: result.length, //This is wrong for a start!
level: 0
}));
setTheGroups(arr2);
}
////////
<DetailsList className={styles.DetailsList}
items={allAssessments.slice((ListPage - 1) * 50, ((ListPage * 50)))}
columns={_detailsListColumns}
groups={theGroups}
selection={selection}
onRenderItemColumn={_onRenderColumn}
/>
But I've hugely overthought it and now got into a mess. The above groups things incorrectly. I hope the above is enough to give you an idea of what I want and doesn't cloud the waters!