Selectable rows in tree grid

Certified Associate Developer

Hello!

I'm trying to implement a tree grid using the gridlayout() component in an Interface. I've been able to make it hierarchical (Once you click on a row, new subrows appear just under it) with loops and local variables to show or hide those subrows

I now need to make the rows selectable on the grid, but I specifically also want that if I click a row, its subrows get automatically selected as well

To give a little more of context, imagine a dictionary of 6 keys where every key defines a level in the tree grid. First all distinct values for the first key appear, and when clicking in one of them, all distinct values for the second key of elements that have that clicked value on the first key appear.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    It should be enough to add a saveInto() to add the IDs of the subrows to the selected items. Do you have any code snippets?

  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

    rows: {
          a!gridRowLayout(
            contents: {
              a!richTextDisplayField(
                value:a!richTextItem("FundHouse Name","STRONG")),
              a!richTextDisplayField(value: ""),
              a!richTextDisplayField(value: "")
            }
          ),
          a!forEach(
            rule!PM_FilterTreeGridAPI(local!revenues, "sFundHouseName"),
            {
              a!localVariables(
                local!show2: false,
                local!value: fv!item,
                {
                  a!gridRowLayout(
                    contents: {
                      a!richTextDisplayField(
                        value: a!richTextItem(
                          text: if(
                            local!show2,
                            concat(char(9), "- ", fv!item),
                            concat(char(9), "+ ", fv!item)
                          ),
                          style:if(local!show2,
                          "STRONG","PLAIN"),
                          link: a!dynamicLink(
                            saveInto: a!save(local!show2, not(local!show2))
                          )
                        )
                      ),
                      a!richTextDisplayField(value: ""),
                      a!richTextDisplayField(value: "")
                    }
                  ),
                  a!gridRowLayout(
                    showWhen: local!show2,
                    contents:{a!richTextDisplayField(value:a!richTextItem(concat(char(9),"Distributor Name"),"STRONG")),
                    a!richTextDisplayField(value:""),
                    a!richTextDisplayField(value:"")}
                  ),
                  a!forEach(
                    rule!PM_FilterTreeGridAPI(
                      rule!PM_FilterTreeGridfran(local!revenues, { local!value }),
                      "sDistributorName"
                    ),
                    {a!localVariables(
                    
                    ...

    My code looks like that (I stopped in local variables since there I repeat the process until I finish with the 6th key). To that I would need to add that "hierarchical select" I'm looking for. How would your structure be added to that?

  • 0
    Certified Lead Developer
    in reply to franciscoalfonson0001

    I assume that you use the OOTB selection feature of the grid. Each row has a unique ID, adding this ID to the selectionValue parameter of the grid will make these rows selected.

    Now, with some logic in the selectionSaveInto, you should be able to add all sub-rows on selection of a parent row.

  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

    Hello,

    I've assigned an unique id to every row in the grid ("(Value in first key)-(Value in second key)-..."). I've also made a "Begin with" rule to find all elements in an array that start with a particular string. Is there any way to get all the ids of the grid rows? Or is there another way to approach the situation to make the "hierarchical selection" possible?

  • 0
    Certified Lead Developer
    in reply to franciscoalfonson0001

    So, when you expand a top level item, you implemented some logic to find the child items. I suggest to use a similar logic for adding the IDs to the selected items for selection.

  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

    Hello,

    to get the subrows to appear, I also used the values of the previous keys so, for example, to get the values for the 5th level, the logic included the values of the 4 previous ones.

    I intended to use the Id system I wrote before because if I could get to the Ids of the rows, I'd just search all the Ids that started with the Id of the row I selected.

    I also thought about using the element itself as an id, but I wouldn't be able to use the same logic that I applied to get the subrows (as it used the values of the previous values as well)

Reply
  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

    Hello,

    to get the subrows to appear, I also used the values of the previous keys so, for example, to get the values for the 5th level, the logic included the values of the 4 previous ones.

    I intended to use the Id system I wrote before because if I could get to the Ids of the rows, I'd just search all the Ids that started with the Id of the row I selected.

    I also thought about using the element itself as an id, but I wouldn't be able to use the same logic that I applied to get the subrows (as it used the values of the previous values as well)

Children
No Data