web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Add item at the first ...
Power Apps
Unanswered

Add item at the first position when using Patch in a local collection

(0) ShareShare
ReportReport
Posted on by 68

Hi Everyone, 

 

I have a local collection ("localColl) that is populated from the SharePoint list and I have set this as a DataSource to the Gallery. I am adding a new item using the below code:

Patch(
 localColl,
 Defaults(localColl),
 {
 'Name (Title)': "New Project",
 Status: {Value: "Enable"}
 }
)

The above code adds the record in the bottom of the Gallery. But I need to make this add the record at the first index of the Gallery as there will be more items in the Gallery. 

 

Previously, I had set the SharePoint list as the DataSource directly to the Gallery and in that case, I achieved it using the Sort function. But since there are more records, there is a time delay when adding the item and then sorting and refreshing the DataSource (like it takes around 4secs for the records to appear after refreshing). 

 

Also since its a New item that is getting added, I am storing it in the local collection and then I am adding it to the SharePoint list only when the Save button is clicked by the user. So can anyone please help me out here to add the new record in the top of the local collection such that Gallery displays it in the first poisition.

 

So can an

Categories:
I have the same question (0)
  • lenro Profile Picture
    194 on at

    hi @sgokul95 

    To do it, you need to have either date of when it was edited or a row number in your list. By having it you will be able to sort your gallery

  • C-Papa Profile Picture
    1,836 on at

    Firstly i would avoid using the Refresh() function this is what is taking the time and is often not required unless someone else is changing the database in another app. 

     

    You just need to add a sortbycolumns to the gallery to solve this and without the refresh it should be almost instant as long as there are not huge amounts of records in the collection. Remember, sort by columns works on more than one column. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 395

#2
WarrenBelz Profile Picture

WarrenBelz 352 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 287 Super User 2026 Season 1

Last 30 days Overall leaderboard