Allowing limited number values displaying in Drop down?

Certified Senior Developer

Hello,

 

 

 How Can I display the limited number of values in the Dropdown Component?

 

 

Thanks in Advance

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    Hi @ 

    There are various options to display limited number of choice options to display in a drop-down component, for example:

     

    Let's assume you are pulling few rows from your reference table to display it under the drop-down component. And assume you have more than 10 rows available in DB but you just want to limit the set of options to 10 then, you can make the use of pagingInfo while querying the data, as mention below:

    rule!yourQueryEntity(
        pagingInfo: a!pagingInfo(
            startIndex: 1, 
            batchSize: 10, 
            sort: a!sortInfo(
                field: "your Field Name/Primary Key Column",
                ascending: true()
            )
         )
    )

    In this case irrespective of how many rows you have in your DB, Query Entity will only pull 10 rows sorted by the provided column and will display the same under dropdown component.

     

    But, out of interest, why do you want to show only few options under a drop-down, is that based on some conditions?

  • 0
    Certified Senior Developer
    in reply to aloks0189
    Hi,
    Another option would be to have an active and inactive indicator which can be used to limit dropdown options and query entity can be modified to show or retreive the same
  • Hi Sandeep,
    You can do this in multiple ways.

    1. Adding a filter condition if the values are from DB.
    2. Using remove function to remove the indexes not required. for ex:
      load(
      local!data: {1,2,3,4,5,6,7,8,9,10},
      local!indexToRemove: {1,5},
      local!drop,
      a!dropdownField(
      label: "Test",
      choiceLabels: remove(local!data,local!indexToRemove),
      choiceValues: remove(local!data,local!indexToRemove),
      placeholderLabel: "Please Select",
      value: local!drop,
      saveInto: local!drop
      )
      )
  • 0
    A Score Level 2
    in reply to ekanshj
    All the above ways are good please be remember while limiting the drop down values , Existing instances should not break throwing pink screen error message that the value supplied is not in the choice values list.
  • All of these will work, and I agree that you will want to double check that your solution does not break any existing instances as this can be a common pitfall.
  • 0
    Certified Senior Developer
    in reply to aloks0189

    Hi,

    Thanks for the reply everyone,
    My exact question is In the database table there are 50 rows of data. Initially, in the dropdown, I need to display 10 rows and below the dropdown, I need to give one link i.e "showall", If user Clicks that showall link I need to display all the rows(50) in the drop-down.


    Thanks.

  • +1
    Certified Lead Developer
    in reply to sandeepn

    Hi @sandeepn ,

    To achieve this you can follow below mentioned steps.

    1. Define a variable on load() of this interface

    local!paging_pagingInfo: a!pagingInfo(
        startIndex: 1,
        batchSize: 10,
        sort: a!sortInfo(
          field: "Your Primary Key/ or any other column",
          ascending: true()
        )
      )

    2. Now call the Query Entity Rule by passing this local variable as an input for PagingInfo. this means initially Query Entity will pull 10 rows only. And store the query result into a local Variable, say local!datasubset.

    3. Define and configure the dropdown.

    4. Define a Link Field with a Dynamic Link (say, Show All) below/beside your dropdown depending on your requirement and configure it as follows.

    a!linkField(
            links: a!dynamicLink(
            label: "Show More",
              saveInto: {
                a!save(
                  local!paging_pagingInfo, /* Variable declared on load */
                  a!pagingInfo(
                    startIndex: 1,
                    batchSize: - 1,
                    /*Querying all the rows*/
                    sort: a!sortInfo(
                      field: "Your Primary Key/ or any other column",
                      ascending: true()
                    )
                  )
                ),
                /*Assuming yourQueryEntity is the name of your rule to Query the data.*/
                a!save(
                  local!datasubset,
                  rule!yourQueryEntity(pagingInfo: local!paging_pagingInfo)
                )
              }
            )
          )

    Hope this will help.