Hello Friends,
Welcome back with another post on PowerApps. We are starting a series of posts in which we will learn about-
- Nested Gallery
- Expand / Collapse (individual master child record set)
- Expand All / Collapse All
- Alternate row color
We will learn all these features one by one. So let's start-
- Before starting, we need a SharePoint List having below columns-
- OrderID
- ItemName
- ItemQuantity
- We have kept the list simple to just show the functionality.
- Now add 5-6 orders with each having multiple items.
- Now click on App Launcher (grid of 9 dots at top left corner) and click on PowerApps to open the PowerApps maker platform.
- I am creating PowerApps in Tablet mode so that the display of nested gallery should be clear.
- First of all, add connection with SharePoint list. For this, click on Data icon from left navigation menu, click on Add Data. Now select the SharePoint connector. Select the Site and then list "OrdersList".
- Now, add a button at bottom right corner which will load the data from SharePoint to local collection.
- Click on Insert >> Button. Rename it btnLoadData. Set Text as "Load Data".
- Add below function on "OnSelect" property-
ClearCollect(OrdersListCollection,GroupBy(OrdersList,"OrderID","ListItemDetails"));
- This function will load the data from SharePoint list into a local collection "OrdersListCollection" with grouping on OrderID. The grouped data will reflect under column "ListItemDetails". It means, the local collection will have two column-
- OrderID
- ListItemDetails
- Now we will add gallery control on screen. For this, choose the gallery of type "Blank flexible height". The reason behind this is that we will expand the item based on the number of child items.
- Set the-
- Height property of gallery as "Parent.Height"
- Width property as "1000"
- Items property as "OrdersListCollection"
- Now click on the Edit icon of item template as shown in below screenshot-
- Add a label and set it's-
- Width as 400
- Position X as 0
- Position Y as 0
- FontWeight as Bold
- Height as 50
- Fill as RGBA(241, 244, 249, 1)
- Rename it as lblOrderID
- Text as Concatenate("Order ID: ",Text(ThisItem.OrderID))
- Add one more label and set it's-
- Width as 585
- Position X as 400
- Position Y as 0
- FontWeight as Bold
- Height as 50
- Fill as RGBA(241, 244, 249, 1)
- Rename it as lblCustomer
- Text as Concatenate("Customer: ",LookUp(OrdersList,OrderID = ThisItem.OrderID,'Created By'.DisplayName))
- This will show the Order ID and the Customer name. Rename this gallery as "GalleryOrderMaster".
- Now we will add one more gallery, which will show the Items associated with that particular Order ID. Once again, click on edit icon as shown in Step 20 and add another gallery of type "Blank flexible height". Rename it as "GalleryItemsDetails".
- Set-
- Position X as 50
- Position Y as 50 (you may set it dynamic by specifying lblOrderID.Height + lblOrderID.Y)
- Width as 885
- Height as 100 (we will make it dynamic later in code)
- Items as ThisItem.ListItemDetails
- Now we will add two labels to show the ItemName and ItemQuantity.
- Add first label and set-
- Name as lblItemName
- Text as ThisItem.ItemName
- Position X as 0
- Position Y as 0
- Width as 300
- Height as 50
- Similarly, add another label and set-
- Name as lblItemQuantity
- Text as ThisItem.ItemQuantity
- Position X as 300
- Position Y as 0
- Width as 300
- Height as 50
- This way you can show nested items. The basic part is complete. Now, if you execute the PowerApps, you will find that the height of nested gallery is fixed. So, we will make it dynamic. For this, set the Height of GalleryItemDetails as "(CountA(ThisItem.ListItemDetails.ItemName)+1)*50". We have added +1 to make sure there should be no scrollbar.
- This way we can achieve nested gallery functionality. In next post, we will discuss about Expand / collapse feature in nested gallery.
- UPDATE:
- Some times, you may find that if the data in nested gallery is too large, then the behavior of parent-nested gallery becomes abnormal.
- As you can see, Parent Items (Kamal, Manoj...) are inline with Child Items (Item-491, Item-492...). (Below is the dynamic height code which you will read in my next articles of this series).
- The Height code is-
If( ThisItem.OrderID = ParentGallery.Selected.OrderID, (CountA( Filter( CollChild, OrderID = ThisItem.OrderID ).ItemName ) + 1) * 50, 0 )
- To avoid this situation, we need to fix the height of child gallery upto a max limit. But the problem is that, there is Max Height property available for Gallery control.
- So, we have prepared a workaround to overcome this problem. We have Min function. We will make use of it.
- Let's modify the code for Height (I am taking maximum height for child gallery as 400)-
If( ThisItem.OrderID = ParentGallery.Selected.OrderID, Min( (CountA( Filter( CollChild, OrderID = ThisItem.OrderID ).ItemName ) + 1) * 50, 400 ), 0 )
- After implementing this code, the height of child gallery is set to maximum 400 as the calculated height was much greater than 400. Therefore, Min function gave 400 as output.
- In case if the calculated height is less than 400, in that case, the Min function will gave the calculated value as output.
With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.
Stay Safe !
Stay Healthy !
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.