Appian Community and Appian Academy are being upgraded. From July 24–August 3, the Appian Community will be in read-only mode. During this time, the site will be read-only and user registration will be disabled. We apologize for any inconvenience this may cause, but a more secure, stable, and performant Community experience is coming soon!

The new Appian Community launches August 3, followed by Appian Academy on August 7. During the migration, Appian Community Edition, Appian Academy, Documentation, Certifications, Instructor-led Customer Training, Partner Sales Training & Accreditation, and Forum (for Appian Partners and Customers only) will remain available.

Grid Link and display text

a!localVariables(
  local!gridData:todatasubset({{id:1},{id:2},{id:3}}),
  local!selectedId,
  local!clicked:false(),
  local!display:{{id:1,name:"abc"},{id:2,name:"pqr"}},
  {
    
   a!gridField(
     label:"Click Links",
     data:local!gridData.data,
     columns: {
       a!gridColumn(
         label:"Link",
         value:a!linkField(
           label: fv!row.id,
           links:a!dynamicLink(label:fv!row.id,value:fv!row.id,
           saveInto: {local!selectedId,a!save(local!clicked,if(local!clicked,false,true))})
         )
       )
     }     
   ),
   a!textField(
     label:index(local!display.name,wherecontains(local!selectedId,tointeger(local!display.id))),
     showWhen: local!clicked
   )
  }
  
)

I have a grid field with links in multiple rows. Based on the selected link, a text field should be displayed. But, here's a twist, For eg, I have 3 links: Link 1, link2, link3.

On selecting link 1, data should be displayed based on the selection. On selecting the link again, it should dissappear. On selecting Link2, data should again display based on the selection. On selecting link 3 (while data2 is already displayed), instead of disappearing, data 3 should appear.

I have this code snippet, but it's taking two clicks to show the next data. I want to see the data when the user jumps from 1 link to another.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Here's how I'd suggest you re-write the above code:

    a!localVariables(
      local!gridData: todatasubset({ { id: 1 }, { id: 2 }, { id: 3 } }),
      local!selectedId: tointeger(null()),
      local!clicked: not(isnull(local!selectedId)),
      local!display: {
        { id: 1, name: "abc" },
        { id: 2, name: "pqr" }
      },
      {
    
        a!gridField(
          label:"Click Links",
          data:local!gridData.data,
          columns: {
            a!gridColumn(
              label:"Link",
              value: a!richTextDisplayField(
                value: a!richTextItem(
                  text: fv!row.id,
                  link: a!dynamicLink(
                    value: fv!row.id,
                    saveInto: {
                      local!selectedId
                    }
                  )
                )
              )
              /*a!linkField(*/
                /*label: fv!row.id,*/
                /*links: a!dynamicLink(*/
                  /*label: fv!row.id,*/
                  /*value: fv!row.id,*/
                  /*saveInto: {*/
                    /*local!selectedId,*/
                    /*a!save(*/
                      /*local!clicked,*/
                      /*if(local!clicked, false, true)*/
                    /*)*/
                  /*}*/
                /*)*/
              /*)*/
            )
          }     
        ),
        a!textField(
          label: index(
            local!display.name,
            wherecontains(
              local!selectedId,
              tointeger(local!display.id)
            )
          ),
          showWhen: local!clicked
        )
      }
    )

    Here we make use of the auto-updating nature of a!localVariables() values by setting "local!clicked" to simply key off of whether there's an ID selected.  That way, you don't need to waste an extra saveInto (and the accompanying if() logic surrounding it to determine its new value).

    Also - don't use a!linkField.  We have a!richTextDisplayField() now and it's far more usable, more flexible, etc.

  • Hi Mike, Thanks for your answer and your tip on the link field. This solution does not hide the display text. The requirement is, when I click link 1, value should be shown, when I click it again, it should be hidden. But, instead of clicking it again, if I click Link2, the corresponding value should be displayed.

    I way I coded local!click was doing the same thing, but it was taking 2 clciks to display the second value.

  • +1
    Certified Lead Developer
    in reply to ankitab254

    Ah, I missed that piece in my implementation somehow.

    That's pretty simple to add using a little if() logic in the link saveInto, however:

    a!richTextDisplayField(
      value: a!richTextItem(
        text: fv!row.id,
        link: a!dynamicLink(
          value: fv!row.id,
          saveInto: {
            a!save(
              local!selectedId,
              if(
                local!clicked,
                if(
                  local!selectedId = fv!row.id,
                  null(),
                  fv!row.id
                ),
                fv!row.id
              )
            )
          }
        )
      )
    )

Reply Children
No Data