Showing results for 
Search instead for 
Did you mean: 
Helper I
Helper I

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

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:

        '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

Helper IV
Helper IV

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

Super User
Super User

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. 

Helpful resources

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.


New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (2,492)