How to append results in a grid

Hi everyone, 

 

I am having trouble with a grid and would like to get any help possible.

I have a search field where a user can search for a location.

Once they hit search and the location is available, they are able to select it.

They are then able to add the selected location to a second grid below the first grid, which shows all the locations that were selected. 

 

However, I am having an issue when it comes to if the user wants to search for another location and add it to the second grid. When they do so, the second grid refreshes all the data. I was wondering if there was a way to append the selected locations to the second grid so that the all selected results would show?

 

Any help would be appreciated!

  Discussion posts and replies are publicly visible

Parents
  • chynnak

    I think what you are looking for something similar to what I have given below. This is a simple representation of similar requirement. Might help in understanding what needs to be done in your scenario.

    i have used a drop down instead of a search grid in this case but concept should be similar.

    =load(
      local!paginInfo:a!pagingInfo(
        startIndex:1,
        batchSize:3
      ),
      local!location,
      local!datavalue:{},
    
    a!formLayout(
      label: "Location sample formm",
      firstColumnContents: {
        with(
          local!datasubset: todatasubset(local!datavalue,local!paginInfo),{
        a!dropdownField(
          label: "location",
          choiceLabels:{"norwich","london","york","manchester"},
          choiceValues:{"norwich","london","york","manchester"},
          placeholderLabel:"----choose val-----",
          labelPosition: "ABOVE",
          value:local!location,
          saveInto: {local!location,
          a!save(local!datavalue,append(local!datavalue,{name:save!value}))
          },
          refreshAfter: "UNFOCUS",
          validations: {}
        ),
          a!gridField(
          label: "selected locations",
          totalCount:local!datasubset.totalCount,
          columns: {
            a!gridTextColumn(
              label: "Name",
              field: "name",
              data: index(local!datasubset.data,"name",null)
                
              )},
              emptyGridMessage:"No locations selected",
              value:local!paginInfo,
              saveInto:local!paginInfo
          
        )
          }
        )
      },
      secondColumnContents: {
        /* Add components here for a two-column form */
      },
      buttons: a!buttonLayout(
        primaryButtons: {
          a!buttonWidgetSubmit(
            label: "Submit",
            style: "PRIMARY",
            saveInto: {}
          )
        },
        secondaryButtons: {
          a!buttonWidgetSubmit(
            label: "Cancel",
            style: "NORMAL",
            value: true,
            saveInto: ri!cancel,
            skipValidation: true
          )
        }
      ),
      validations: {}
    )
    
    )

     

    Regards

    Suresh

  • Hi Suresh,

    I currently have something like this in the a!save piece of my code.
    a!save(
    local!selectedlocations,
    index(
    local!locationsData.data,
    wherecontains(
    local!gridSelection.selected,
    local!locationsdata.identifiers
    )
    )
    )

    It seems that to make my code similar to yours, I would a!save(local!selectedlocations,append(local!selectedlocations,{name:save!value}))

    what would value be in this case if I do not have a dropdown field like you did?
  • 0
    Certified Lead Developer
    in reply to ck0220
    Does the new location get added immediately when the user selects it on the grid, or do they select it on the grid and then press a button (for example) to commit the addition? Are they able to select more than one item at a time?
  • Let's say in the search bar, they type "New". Once they hit search, the locations that come up would be something like New York, New Jersey, New Delhi, etc. They're able to select as many locations as they please and then hit the "add" button. This button adds the selected locations to a grid below it. The issue comes in when the user wants to now search something like "North", all the "New" locations are now removed from the grid.
  • hi chynnak,

    I think the problem in your code is you are replacing the datasubset variable in your a!save. In the example I have given you, you can see how the updated values are used to generate the datasubset variable as this is used as a with variable.

    If you save new values to the datasubset.data which you use in the grid, obviously it will remove all previous values and update with new values. So keep those separate have a separate load variable to save the selected values then use those to generate the datasubset which you can use in your grid.

    Regards
    Suresh
  • +1
    Certified Lead Developer
    in reply to ck0220

    Based on this description, the code you posted earlier is pretty close.  I think it should just need a slightly more complicated structuring of your a!save, to include the append() operation so as to not overwrite previously saved data when you click "Add" for subsequent additions.

    Maybe something like:

    a!save(
      local!selectedLocations,
      append(
        local!selectedLocations,
        index(
          local!locationsData.data,
          whereContains(
            local!gridSelection.selected,
            local!locationsData.identifiers
          )
        )
      )
    )

Reply
  • +1
    Certified Lead Developer
    in reply to ck0220

    Based on this description, the code you posted earlier is pretty close.  I think it should just need a slightly more complicated structuring of your a!save, to include the append() operation so as to not overwrite previously saved data when you click "Add" for subsequent additions.

    Maybe something like:

    a!save(
      local!selectedLocations,
      append(
        local!selectedLocations,
        index(
          local!locationsData.data,
          whereContains(
            local!gridSelection.selected,
            local!locationsData.identifiers
          )
        )
      )
    )

Children