How to refresh a datagrid without committing changes first

1
Imagine a page in which a main object ('Playlist') is maintained. It contains two datagrids.  The first one shows all occurrences of 'Song' which are associated with the main object 'Playlist'. This grid is filled by a Xpath: [Music.Playlist_Song = '[%CurrentObject%]'] The second grid shows all occurrences of 'Song' which are NOT associated (yet) with the main object. This grid is filled by this Xpath: [not(Music.Playlist_Song = '[%CurrentObject%]')] First datagrid contains a button "associate" which runs a microflow that adds the association between the Playlist and a Song, through a Change with refresh in client and no commit.  The second datagrid contains the button "disassociate" which runs a microflow that removes the association (with refresh in client, and no commit). The problem is that the datagrids do not refresh after running either microflow. Setting the Change to 'commit' does solve this issue, but in that case I cannot cancel/rollback the transaction. Am I missing something here? How can I solve this, so I can refresh both grids and still being able to rollback the changes?
asked
1 answers
2

Hi Cor,

  You are correct that Xpath data sources are always executed on the database.  The only way for the lists to show new data is to retrieve new entries from the database.  Refreshing the object without committing will not show your changes because when you refresh, the XPath is executed again against the contents of the database. 

  To populate your data using objects changed in memory but not yet committed you will need to use the 'association' database source  This will allow you to change your associations and refresh it without going to the database.  

  There will be one final piece to the puzzle, however: how can you keep track of the songs that do not have the association yet?  The default association data source will not let you use logic like not(playlist_song)… since that function is executed in SQL on the database by Mendix when you write your XPaths.  You will need to do something a little clever to get around that, like building another association between your playlist and song called 'notselected' and upon opening up the playlist page, you put set the association for all songs that are NOT on the playlist.  Then when the user is on the page you will have two clean associations to use for your list views.  

answered