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