When you create model driven apps you would expect to create Dataverse views to display your data, but how about Canvas apps? In this post an easy way to create a dropdown to control your data in your galleries.
Dataverse Views
Table of Contents
Within Dataverse we can create tables and for Tables we can create views, that display either a prefiltered number of records or it would give us a set of columns that we can display to the user.

Galleries in Canvas Apps
Within Canvas apps we can create galleries, so that we can display data from a datasources. So Typically we could specify a table to feed our Gallery.

Set the View in a Gallery
Now you could select the View of the Gallery using the dropdown in the Gallery properties, however if we want to leave it up to the user to select the views, then we might want to add a drop down to our screen.

Create a Dropdown with all views
We can add a dropdown that gives us all the Views available within the table that we have selected as a data source. Using the Choices function we can then get a list of views.

Use the dropdown to control the Gallery data
Now all we need to do is update the Items property on the gallery to include our view selected in the Dropdown control and we are done.

Benefits
Ok, this may not look that much better than just adding the filters to your code in the Canvas app. However, by using views the queries will run more effectively as you will not see any delegation errors. Following the general rule of thumb that the data manipulation should be done as closely as possible to the data rather than the user interface.
By letting your data layer handle the complexities of the data filtering, you should see performance improvements in your apps.
So compare these views a bit with SQL views or stored procedures. If you can use views or stored procedure in SQL that that is always better than reconstructing the same within your apps that read their data from SQL.
And how about accessing data from multiple tables. Or filtering data by having related records in another table. Using Dataverse views makes that all possible.

Discover more from SharePains
Subscribe to get the latest posts sent to your email.
Any idea how to use a Dataverse view as the filter but to also have the sorting from the same Dataverse view applied?
You can specify both filters and sort in a single view. What are the difficulties that you are having?