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
          )
        )
      )
    )

  • Wow! That worked perfectly! Thank you. Am I allowed to ask a related question? I was wondering how I would be able to remove the selected locations from the first grid, so that they wouldn't be able to be searched again. So if the user searched New once more (and chose New York and New Jersey the first time), the only option that shows up is New Delhi.
  • 0
    Certified Lead Developer
    in reply to ck0220
    This should be possible, assuming you're using a query entity to construct your locationsData datasubset. Assuming you have it saved as an external rule, pass in a new rule input called "excludeLocations" (text, mulitple), and inside the rule, add logical requirement that if anything gets passed in for "excludeLocations", they will get excluded from the query results.
  • 0
    Certified Senior Developer
    in reply to ck0220

    You can add one more a!save to remove the selected values from first grid like below.

    {

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

    a!save(
    local!allLocations,
    remove(
    local!allLocations,
    whereContains(
    local!gridSelection.selected,
    local!allLocationsData.identifiers
    )
    )
    )

    }

Reply Children
No Data