Objective

Creating multi-level grouping using a SmartObject and a Tree control.

Before You Begin

Start by creating a SmartObject and adding data to it in a specific manner to allow the tree control to display the content in a multi-level grouping format.

Group Stucture Format

  Country

     States

          City

                District

Grouping Structure with content

  South Africa

      Gauteng

           Johannesburg

                 Randburg

How-to Steps

1. When creating the SmartObject that will contain the data, the SmartObject must be designed and data has to be added to it in a specific manner.

You will need to make sure that your SmartObject contains the below three properties when creating it:

  • ID : Autonumber
  • Type : Text
  • ParentID : Text OR Number

2. After your SmartObject has been created, the data added to it also needs to be added in a specific manner. The ID will be created automatically as it is set to an autonumber however, the Type and ParentID need to be specified.

When you specify the Type you can add the text that you need it to be, the ParentID will be the group identifier for the Type. 

For example: If I want my grouping to look like below:

Group Names

    Group 1

        User 1

        User 2

    Group 2

        User A

3. I will need to add the First Type which would be "Group Names." This will then have a ParentID of "0" (zero) as zero is the indicator of the parent in the tree control data source. The Second Type "Group 1" will then need the Type:"Group Names" ID value set to be the ParentID for Type:"Group 1" which would mean that Group 1 would then become a child of the parent group. This will result in the below structure:

TreeSMO.png

4. After your SmartObject is set up and contains data you can simply bind it to the Tree control as its data source as below:

TreeDS.png

5. Then save, finish and Run your view. The data will then be displayed like the results below:

TreeR.png

Please also see K2 Documentation - Tree Control