Do you know how to add new row in Power Apps Gallery Control? Here, I will explain the various ways to add a new row in the Power Apps Gallery.
When using the Gallery in Power Apps, we frequently customize or apply conditional formatting based on our needs. One of the most common things users may desire or need from time to time is to add a new row to the gallery.
In this Power Apps article, I have explained two approaches to adding new rows in the Power Apps gallery. Such as:
- Power Apps Gallery add a new row using the Patch Function
- Power Apps Gallery add a new row using the Variable
How to Add New Row in Power Apps Gallery Control
Let us see how to add a new row in Power Apps Gallery Control. Check out the below examples.
Example – 1: [Using Power Apps Patch Function]
Unfortunately, We can not add a new row or item directly to the PowerApps Gallery control. There is no way to achieve this directly. Alternatively, we can use the PowerApps Patch Function. Let’s do this.
1. I have a Gallery control on the screen where the records are retrieved from a SharePoint List called Products. The list contains various fields with different Data types:
Column | Datatype |
---|---|
Title | Single line of text |
Vendor | Choice |
Customer Name | Single line of text |
Quantity | Number |
Price | Currency |
Comments | Multiline text |
The SharePoint list looks like the below screenshot.
2. The screenshot below represents a Power Apps gallery control and a Button control (Create Item). The gallery contains the Title, Quantity, and Comments columns retrieved from the SharePoint list.
3. The button helps create a new record in the SharePoint list once the user clicks on it.
4. Select the Button and apply the below formula on its OnSelect property:
OnSelect = Patch(
Products,
Defaults(Products),
{
Title: "EarDope",
Quantity: 5,
Comments: "Nice Product"
}
)
Where,
“EarDope“, 5, “Nice Product” = Provide the new items/values
5. Now, Save and Preview the app. Tap on the Create Item button. Once you click on it, a new record has been created in the list, and the PowerApps Gallery control is shown below.
6. If the new record does not appear in the gallery control, refresh the SharePoint List data source connector. Then, you can view the new row in the gallery.
7. Meanwhile, if you go to the specific SharePoint list, the new item has also been added, as shown below.
This is how to use the Patch function to add a new record in the Power Apps gallery control.
Example – 2: [Using Power Apps Variable]
1. Create a Power Apps Collection on App’s OnStart property:
OnStart = ClearCollect(
colTravelDetails,
{
FullName: "James",
Destination: "London",
TravelDate: "16/10/2023"
},
{
FullName: "Miriam",
Destination: "Paris",
TravelDate: "20/10/2023"
},
{
FullName: "Delve",
Destination: "Dubai",
TravelDate: "25/10/2023"
},
{
FullName: "Adele",
Destination: "Australia",
TravelDate: "30/10/2023"
}
);
Where,
- colTravelDetails = Collection Name
- FullName, Destination, TravelDate = Collection Headers
- “James“, “London“, “16/10/2023” = Collection Records
2. Insert a Vertical Gallery Control and set its Items property as:
Items = colTravelDetails
colTravelDetails = Created Collection Name
Run the App’s OnStart property once. you can see the collection records as shown the image below.
3. Now set a variable and values on Screen’s OnVisible property:
OnVisible = Set(
varNewTraveller,
{
FullName: "Harry",
Destination: "USA",
TravelDate: "02/11/2023"
}
);
Where,
- varNewTraveller = Variable Name
- FullName, Destination, TravelDate = Collection Headers
- “Harry“, “USA“, “02/11/2023” = Add new record or value
4. Next, go to the App’s OnStart property and apply the code below:
OnStart = ClearCollect(colTravelNew,colTravelDetails);
Collect(colTravelNew,varNewTraveller);
Where,
- colTravelNew = New Collection Name
- colTravelDetails = Collection name that you have created before
- varNewTraveller = Created Variable Name
5. Select the gallery and set its Items property as:
Items = colTravelNew
6. Save and Publish the app. Run the OnStart property of the App once. Then, the new record will be added to the gallery, as shown below.
This is how to use the variable to add a new record in the Power Apps gallery.
Conclusion
Now I hope you have some idea to add new row in Power Apps Gallery Control. I have explained two methods to insert a new row into the Power Apps Gallery here. Such as:
- Add a new row to Power Apps Gallery using the Patch Function
- Power Apps Gallery add a new row using the Variable
Additionally, you may like some more Power Apps tutorials:
- Sort Gallery by Person Column in Power Apps
- Select Multiple Items in Power Apps Gallery Control
- How to Sort Power Apps Gallery By ID
- Power Apps Sort Distinct Filter
- Power Apps Gallery Conditional Formatting
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com