How to filter some data in memory (without DB queries)

Certified Senior Developer

Hi,

I'm coding a simple CRUD sub-interface that is integrated inside a parent interface :
A grid displays the lines of the table, and each line contains buttons to edit or remove lines. There is another button to allow to add lines in the Grid.

All theses actions are made in memory through a Rule Input to store data.
At the end, and only at the end, the process store the data in the DB.

Now I would need to filter the lines in the grid (ex : display Docs only, or Photos only) but I need to still do it in memory.

Example:

# Mark           Model       Doc
1 Wolwagen  Golf          document
2 Wolwagen  Polo          photo
3 Nissan        Titan         photo
4 Nissan        Armada    document

To simulate filters, is there any way to do it with Rule Inputs function or mecanism? (I can't use DB query filters).
Is there any way do it without storing the data in 2 differents RI (RI_Docs and RI_Photos) ?

I would need for example a "Show line when" grid attribute, or a way to memory filter the RI...

If you have any idea?

Regards

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    You should be able to accomplish this fairly easily via local variables and your basic Appian array functions.

    Edit: attaching one-form example using all local variables.  local!cars can simply be swapped out with a rule input of your needed CDT type, then adjust the property names as needed.

    a!localVariables(
      local!cars: {
        a!map(id: 1, brand: "vw", model: "golf", doc: "document"),
        a!map(id: 2, brand: "vw", model: "polo", doc: "photo"),
        a!map(id: 3, brand: "nissan", model: "titan", doc: "photo"),
        a!map(id: 4, brand: "nissan", model: "armada", doc: "document")
      },
      
      local!filterChoices: {"document", "photo"},
      local!filterValue: null(),
      
      local!filteredSelection: if(
        isnull(local!filterValue),
        local!cars,
        index(
          local!cars,
          wherecontains(
            local!filterValue,
            local!cars.doc
          ),
          local!cars
        )
      ),
      
      
      a!formLayout(
        label: "Cars Grid",
        
        contents: {
          a!dropdownField(
            choiceLabels: local!filterChoices,
            choiceValues: local!filterChoices,
            placeholder: "-- filter by attachment type --",
            value: local!filterValue,
            saveInto: local!filterValue
          ),
          
          a!gridField(
            data: local!filteredSelection,
            columns: {
              a!gridColumn(
                label: "Brand",
                value: fv!row.brand
              ),
              a!gridColumn(
                label: "Model",
                value: fv!row.model
              ),
              a!gridColumn(
                width: "NARROW",
                helpTooltip: "Attachment Type",
                value: fv!row.doc
              )
            }
          )
        }
      )
    )

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    Waouh...It's so simple... I'm surprised I dit not think such a solution :-) :-)
    Thanks a lot Mike.

Reply Children