Delete one or more rows of data in a read-only paging grid.
This design pattern is not recommended for offline interfaces because reflecting immediate changes in an interface based on user interaction requires a connection to the server.
This scenario demonstrates:
How to to use a!gridSelection for a selectable grid
How to use update a grid by removing a row from that grid
Test it out
Click Remove and note that instructions appear above the grid because you have not selected any rows
Select a checkbox or two, click Remove, and note that the rows are removed from the grid
The Employee Data text field displays the value of the entire test data object
The Removed IDs text field tracks the IDs of rows deleted from the grid. This allows the user to verify that the data has been modified by the delete action.
Notable implementation details
The value of the grid is GridSelection rather than PagingInfo, and the value that the grid returns when the user interacts with it is also a GridSelection. The PagingInfo information is embedded in GridSelection. GridSelection must be used when a grid is configured for selection.
When deleting rows in a paging grid, we need to tell the grid what to display when all the results on a page are deleted. Updating the startIndex of the local!gridSelection.pagingInfo makes sure that the grid does not break when all the entries on the last page are deleted, resetting the view to the new last page of results. Since we're now manually setting our start index when the last page is deleted, we now have to catch when the last result overall is deleted, to correctly set the index to 1.
In this example, we stored the ids of the removed items. This is useful when you want to remove items from an external source, such as a database or another process. If the data on the form is the authoritative version, then you may wish to return the remaining items, rather than what was removed. For that, follow the process below for local!employeeData instead of local!removedIDs.
The wherecontains() function operates on parameters of the same type, so once you switch to your own data, you may have to wrap cast() around local!gridSelection.selected to make it match the type of your identifiers. For example: wherecontains(tointeger(local!gridSelection.selected), local!employeeData.id) would work successfully if local!employeeData is a CDT array where the id field is of type Number (Integer).