0

I'm trying to greate grouped details list using FluentUI controls. I need function to create groups by multiple fields. My test items:

let testItems = [
    {
        "id": "ipofjfe98e9889r3",
        "orderName": "Steel",
        "clientName": "Mark R",
        "clientSex": "male",
        "clientAge": "43",
        "managerName": "Allan Green",
        "orderSum": "36200.72",
        "orderQty": "2"
    },
    {
        "id": "vfjivoeo9w0e0woe",
        "orderName": "Test order 17",
        "clientName": "Michael R",
        "clientSex": "male",
        "clientAge": "30",
        "managerName": "John Smith",
        "orderSum": "3500",
        "orderQty": "5"
    },
    {
        "id": "xfvmj9we0e0-e00e",
        "orderName": "Metal table",
        "clientName": "Bill Gill",
        "clientSex": "male",
        "clientAge": "30",
        "managerName": "John Smith",
        "orderSum": "360",
        "orderQty": "1"
    },
    {
        "id": "vnrvy8383uhfifrf",
        "orderName": "Wood table",
        "clientName": "DD Johnson",
        "clientSex": "male",
        "clientAge": "25",
        "managerName": "John Smith",
        "orderSum": "360",
        "orderQty": "1"
    },
    {
        "id": "jnu4y8v3j9irtjugi",
        "orderName": "Order test",
        "clientName": "Pavlo Kostanian",
        "clientSex": "male",
        "clientAge": "25",
        "managerName": "John Smith",
        "orderSum": "500",
        "orderQty": "2"
    },
    {
        "id": "f5fm5g4ujif33344",
        "orderName": "Something for order",
        "clientName": "Kavlo Postanian",
        "clientSex": "male",
        "clientAge": "25",
        "managerName": "John Smith",
        "orderSum": "420",
        "orderQty": "3"
    },
    {
        "id": "cdjuyidoeeee3322",
        "orderName": "Sofa",
        "clientName": "Camila O",
        "clientSex": "female",
        "clientAge": "30",
        "managerName": "John Smith",
        "orderSum": "900",
        "orderQty": "2"
    },
    {
        "id": "xkxjuhy76e890111",
        "orderName": "Test order 4",
        "clientName": "Marla Singer",
        "clientSex": "female",
        "clientAge": "25",
        "managerName": "John Smith",
        "orderSum": "500",
        "orderQty": "2"
    },
    {
        "id": "fku489ktjjjgjtjjr",
        "orderName": "Good car",
        "clientName": "Viva Cesar",
        "clientSex": "female",
        "clientAge": "23",
        "managerName": "John Smith",
        "orderSum": "8500",
        "orderQty": "1"
    },
    {
        "id": "vjirj8778rer9errr",
        "orderName": "Good wine",
        "clientName": "Mila T",
        "clientSex": "female",
        "clientAge": "23",
        "managerName": "John Smith",
        "orderSum": "300.2",
        "orderQty": "4"
    }
]

Columns:

let testColumns = [
      { key: 'orderName', name: 'Order name', fieldName: 'orderName', isResizable: true },
      { key: 'clientName', name: 'Client name', fieldName: 'clientName', isResizable: true },
      { key: 'clientSex', name: 'Client sex', fieldName: 'clientSex', isResizable: true },
      { key: 'clientAge', name: 'Client age', fieldName: 'clientAge', isResizable: true },
      { key: 'managerName', name: 'Manager name', fieldName: 'managerName', isResizable: true },
      { key: 'orderSum', name: 'Order sum', fieldName: 'orderSum', isResizable: true },
      { key: 'orderQty', name: 'Order qty', fieldName: 'orderQty', isResizable: true },
    ]

In current test case i want to group items by "managerName", then by "clientSex", then by "clientAge". Items are already sorted in correct way by this 3 fields.

I'm expecting this result for groups:

let testGroups = [
      { key: 'Allan Green', name: 'Allan Green', startIndex: 0, count: 1, level: 0, 
      children: [
          { key: 'male', name: 'male', startIndex : 0, count: 1, level: 1, 
              children: [
                  { key: '43', name: '43', startIndex: 0, count: 1, level: 2},
              ] },
      ] },
      {         
        key: 'John Smith', name: 'John Smith', startIndex: 1, count: 9, level: 0, 
        children: [
            { key: 'male', name: 'male', startIndex: 1, count: 5, level: 1, 
                children: [
                  { key: '30', name: '30', startIndex: 1, count: 2, level: 2},
                    { key: '25', name: '25', startIndex: 3, count: 3, level: 2},             
                ] },
              { key: 'female', name: 'female', startIndex: 6, count: 4, level: 1, 
                children: [
                    { key: '30', name: '30', startIndex: 6, count: 1, level: 2},
                    { key: '25', name: '25', startIndex: 7, count: 1, level: 2},
                    { key: '23', name: '23', startIndex: 9, count: 2, level: 2},
                ] }
        ] },     
    ]

I need a function that will be create groups in this way by multiple fields(potentially more than 3).

Then i sort all the groups by number of records and result datails list looks like this: result detilsList

I would be happy for any help.

0 Answers0