Power Apps: Use gallery as a form

 

To transform a gallery into an interactive form within Power Apps, it’s essential to integrate input controls within the gallery structure and establish data bindings. Additionally, incorporating an empty row is crucial to facilitate the addition of new records to the data source.

Data Source Configuration: Our chosen data source is a SharePoint list "Employees", structured to include a pair of single-line text columns for streamlined data entry.


Create a Collection: Use ClearCollect to create a collection that includes all existing Employees from SharePoint list and an empty record for new entries.

// Create a collection with existing Employees

ClearCollect(colEmp, 'Employees'); //'Your SharePoint List'

// Add an empty row for new entry

Collect(colEmp, {Title: "", 'HVEmployee': ""}); // Add other necessary fields

Configure the Gallery: Set the gallery’s Items property to the collection you created.

// Set the Items property of the gallery to the collection
Gallery1.Items = colEmp

Use the Gallery as a Form: Insert input controls within the gallery template to allow users to edit existing items or add new information.

TextInput1.Text = ThisItem.Title

TextInput2.Text = ThisItem.HVEmployee

Patch to SharePoint: Use the Patch function to submit the new data to SharePoint. Add a button control and add the below code to its OnSelect function.

// Patch the data back to SharePoint on submit
Button.OnSelect = Patch(Employees, Defaults(Employees), {Title: TextInput1.Text, HVEmployee: TextInput2.Text});
Refresh(Employees);
ClearCollect(colEmp, Employees);
Collect(colEmp, {Title: "", HVEmployee:""});

No comments

Powered by Blogger.