banner



What Apps Can I Put On My Honda

Adding sort controls to a Power Apps gallery helps users find the information they are looking for more quickly. It ensures the most relevant results are displayed at the top of the gallery and the data can be browsed in an organized way. If you want to deliver an awesome user experience you must include this ability.

I will show you a simple method to create sort controls for every column displayed in a gallery.


Vehicle Sales Information App

The Vehicle Sales Information App allows salespeople at a car dealership to lookup the price of previously sold cars. Salespeople scroll through the gallery to find the car they are searching for and can click on the sort controls to arrange any column in ascending or descending order.

Make a new SharePoint list called 'Car Inventory' with 5 columns: Year (number), Make (text), Model (text), PurchaseDate (date), Price (number). To populate the list with 3,000 vehicles I used a free fake data generator called Mockaroo. Here's a sample of the 1st few rows:

Year Make Model PurchaseDate Price
2009 Mazda MX-5 10/21/2020 13,014
1985 Honda Accord 5/2/2018 16,725
2001 Ford Windstar 10/22/2019 17,198
1994 Mitsubishi Eclipse 2/16/2019 15,617
2003 Lamborghini Gallardo 11/9/2020 14,831

Open Power Apps and create a connection to the Car Inventory list. Then create a gallery and insert labels showing all columns in the SharePoint list.

Place a label above the gallery with a purple fill to act as a table header. Write each column name in the text property of the label and position them to match the data columns inside the gallery.

Creating Sort Controls

A salesperson should be able to click on an arrow icon beside each column name to sort the gallery. Insert a white chevron down icon beside the year column name like this.

When the salesperson clicks on the icon we need to capture which column should be sorted and which direction to sort. The first click should sort by year in ascending order (lowest-to-highest) and a second click should sort in descending order (highest-to-lowest).

Put this code in the OnSelect property of the icon to capture the column name and the sort direction

          UpdateContext({     locSortColumn: "Year",     locSortAscending: locSortColumn<>"Year" Or !locSortAscending })        

Then put this code in the Icon property of the icon so it changes to match the sort direction in locSortColumn.

          If(     locSortColumn<>"Year"      Or locSortColumn="Year" And !locSortAscending,     Icon.ChevronDown, Icon.ChevronUp )        

The icon must be highlighted yellow when it is clicked to indicate which column is actively being sorted.

Use this code in the Color property of the icon to change the color

          If(locSortColumn="Year", Yellow, White)        

Now that we have created the sort control for Year follow the same pattern to create sort controls for Make, Model, Purchase Date and Price.

Finally, we must update the Items code in the gallery to produce the desired sort order. I have chosen to use a SWITCH function combined with a SORT function for each possible value of locSortColumn. This ensures the formula can rely on delegation to perform sort operations and return all the rows in 'Car Inventory'.

          Switch(     locSortColumn,     "Year", Sort('Car Inventory', Year, If(locSortAscending, Ascending, Descending)),     "Make", Sort('Car Inventory', Make, If(locSortAscending, Ascending, Descending)),     "Model", Sort('Car Inventory', Model, If(locSortAscending, Ascending, Descending)),     "Purchase Date", Sort('Car Inventory', PurchaseDate, If(locSortAscending, Ascending, Descending)),     "Price", Sort('Car Inventory', Price, If(locSortAscending, Ascending, Descending)),     'Car Inventory' )        

The gallery now has sort controls for each column.

Combining SORT and FILTER

All galleries used to browse large datasets have both SORT and FILTER controls to help the user find what they are looking for. In the gallery shown below I've added filters for Year, Make and Model.

To FILTER the gallery we would need to write this code in the Items property of the gallery. But how can we combine it with our previous code to SORT the items as well?

          Filter('Car Inventory',  Year=drp_Year.Selected.Value, Make=drp_Make.Selected.Value, Model=drp_Model.Selected.Value)        

We will have to re-use the same FILTER code 5 times within the SWITCH function: once for each possible switch case. The Items property code is quite lengthy but its quick to write if you copy and paste the repeating section. Most importantly, it follows delegation rules and returns the entire dataset.

          Switch(     locSortColumn,     "Year",      Sort(         Filter('Car Inventory',              Year=drp_Year.Selected.Value,              Make=drp_Make.Selected.Value,              Model=drp_Model.Selected.Value         ),         Year,         If(locSortAscending, Ascending, Descending)     ),     "Make",      Sort(         Filter('Car Inventory',              Year=drp_Year.Selected.Value,              Make=drp_Make.Selected.Value,              Model=drp_Model.Selected.Value         ),         Make,          If(locSortAscending, Ascending, Descending)),     "Model",     Sort(         Filter('Car Inventory',              Year=drp_Year.Selected.Value,              Make=drp_Make.Selected.Value,              Model=drp_Model.Selected.Value         ),         Model,          If(locSortAscending, Ascending, Descending)),     "Purchase Date",     Sort(         Filter('Car Inventory',              Year=drp_Year.Selected.Value,              Make=drp_Make.Selected.Value,              Model=drp_Model.Selected.Value         ),         PurchaseDate,         If(locSortAscending, Ascending, Descending)),     "Price",     Sort(         Filter('Car Inventory',              Year=drp_Year.Selected.Value,              Make=drp_Make.Selected.Value,              Model=drp_Model.Selected.Value         ),         Price,          If(locSortAscending, Ascending, Descending)),     'Car Inventory' )        

Did You Enjoy This Article? 😺

Subscribe to get new Power Apps articles sent to your inbox each week for FREE

Questions?

If you have any questions or feedback about Power Apps Gallery Sort Controls forms please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.

What Apps Can I Put On My Honda

Source: https://www.matthewdevaney.com/power-apps-gallery-sort-controls/

Posted by: burkeawking.blogspot.com

0 Response to "What Apps Can I Put On My Honda"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel