6 Replies Latest reply on Jul 15, 2010 2:23 AM by Gregor.Kiddie

    Grouping a collection by a child's property?

    EricJ32 Level 1

      Hi,

       

      I have a data model in the following format:

       

      class Item

           - name:String

           - accounts:ArrayCollection

       

      class Account

           - accountName:String

           - accountType:String

           - transactions:ArrayCollection

       

      class Transaction

           - description

           - transactionDate

           - amount

       

       

      I have an IList of Item objects, each containing severat accounts, each of which have several transactions.

       

      Now, I'll need to display this data in several different ways, but for now, I am struggling with grouping accounts by accountType.

       

      So, if the data looks like this:

      Item { name:Barclays }

           Account { accountName: Barc Current account, accountType: bank }

                Transaction { description: desc1 }

                Transaction { description: desc2 }

                Transaction { description: desc3 }

           Account { accountName: Barc Savings account, accountType: savings }

                 Transaction { description: desc4 }

                Transaction {  description: desc5 }

       

      Item { name:HSBC }

           Account { accountName: HSBC Current  account, accountType: bank }

                Transaction { description:  desc6 }

                Transaction { description: desc7 }

                 Transaction { description: desc8 }

           Account { accountName: HSBC Mastercard, accountType: credit }

                Transaction { description:  desc9 }

                Transaction { description: desc10 }

                 Transaction { description: desc11 }

       

      Then it would be grouped into:

       

      accountType: bank

           Account { accountName: Barc Current account, accountType: bank }

                 Transaction { description: desc1 }

                Transaction {  description: desc2 }

                Transaction { description: desc3 }

           Account { accountName: HSBC Current  account, accountType: bank }

                Transaction { description:  desc6 }

                Transaction { description: desc7 }

                 Transaction { description: desc8 }

       

      accountType: savings

           Account { accountName: Barc Savings account, accountType:  savings }

                 Transaction { description: desc4 }

                Transaction {  description: desc5 }

       

      accountType: credit

           Account { accountName: HSBC Mastercard, accountType: credit }

                Transaction { description:  desc9 }

                Transaction { description: desc10 }

                 Transaction { description: desc11 }

       

      I need this new collection to automatically update when the original data changes.

       

      Any ideas?