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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Gallery does not re-so...
Power Apps
Unanswered

Gallery does not re-sort after changing a date

(1) ShareShare
ReportReport
Posted on by 674
I have a gallery of items that gets sorted and filtered when the user selects a project from a combo box. Sorting is primarily by date. This works fine.  However if I change a date in one of the items using a date picker control, which pushes the updated date into the collection bound to the gallery, sorting does not change initially. If I reselect the date a second time, the gallery then sorts, or if the user reselects something in the combo box above the gallery, it sorts.
 
is there any code to force the sorting to be immediately after changing a date?
Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    153,725 Most Valuable Professional on at
    Hi @55552
    What Is the Items of the Gallery and what is your data source type ? Also what is the code you use to update the date.
  • 55552 Profile Picture
    674 on at
    Here is a screenshot of the gallery:
    The Items come from a Collection (filtered and sorted), and the Collection is populated from a Dataverse table. Here is the code for the Items property of the gallery.
    This code is run when the user selects a Project from the combo box at the top. If necessary, I could also run this code when a date is changed, if there are no other options.
     
    Here is the code in the OnChange property of the date selector to put in the newly selected date: I am updating both the local Collection (that is bound to the gallery items) and the underlying online database table in Dataverse, to permanently save the date change. Both request date and delivery date are updated. A column called DelDateSort is used for sorting. This column is pushed when the user selects the Combo box, and reports a delivery date if present, else use the request date. I am purposely updating this column in the Collection in the code below when the date is changed.
     
  • timl Profile Picture
    36,634 Super User 2026 Season 1 on at
     I think the best thing to do, as you suggest, is to run your ClearCollect/SortByColumns/Filter following the date change.
      
    The call to UpdateIf will update the row(s) in the collection, but it won't re-sort the underlying collection, which would explain the behaviour that you're seeing.
  • WarrenBelz Profile Picture
    153,725 Most Valuable Professional on at
    Hi @55552
    I should have also asked you to post your code in Text - the below is OCR'd so spelling may be an issue.
    Firstly, your Items - there is only one field here that is relevant
    SortByColumns(
       Filter(
          AheadWithDates,
          If(
             IsBlank(PieceUIDSearch.Selected.ElementNo), 
             Not(PieceUIDSearch.Selected.ElementNo in DATA.ElementNo), 
             PieceUIDSearch.Selected.ElementNo in DATA.ElementNo
          ) && 
          (
             (
                (
                   DelivDateOnly <= (Today() - 1) Or 
                   IsBlank(DelivDate)
                ) && 
                !DispatchedYN
             ) Or 
             (
                DelivDateOnly >= Today() Or 
                IsBlank(DelivDate)
             )
          ) && TotalWtLoadSum > 10 && 
          If(
             !IsBlank(LotNumSearch.Selected.Value), 
             LotNumSearch.Selected.Value in DATA.lotNumber, 
             ReReq <> "999"
          )
       ),
       "DelDateSort",
       SortOrder.Ascending,
       "ExtStackContainerNo",
       SortOrder.Ascending
    )
    Your data source Patch is not really relevant
    Patch(
       LoadStatuses,
       LookUp(
          LoadStatuses, 
          LoadNumProjID = LoadNumProjectIDHidden.Text
       ),
       {
          ProjectID: varProject,
          ProjectName: varProjectName,
          LoadNumInt: varLoadNumber,
          PiecelD: varPieceList,
          RequestDate: PickReqDate.SelectedDate,
          DeliveryDate: PickReqDate.SelectedDate,
          RequestorEmail: User().Email,
          ReRequest: 
          If(
             !IsBlank(PickReqDate.SelectedDate) && 
             varReReq = "Yes", 
             "No"
          ),
          UserReqDate: Now()
       }
    );
    The UpdateIf of the Collection again has one item in question
    UpdateIf(
       AheadWithDates,
       ExtStackContainerNo = varLoadNumber,
       {
          ReqDateOnly: DateValue(Text(PickReqDate.SelectedDate, DateTimeFormat.ShortDate)),
          ReqDateSort: PickReqDate.SelectedDate,
          ReqDate: PickReqDate.SelectedDate,
          DelivDate: PickReqDate.SelectedDate,
          ReReq: 
          If(
             !IsBlank(PickReqDate.SelectedDate) && 
             varReReq = "Yes", 
             "No"
          ),
          DelDateSort: 
          If(
             !IsBlank(DelivDateSum.Text), 
             DateValue(DelivDateSum.Text), 
             PickReqDate.SelectedDate
          ),
          UserRqDate: Now()
       }
    )
    So what is in DelivDateSum.Text and have you checked that it (or PickReqDate) is updating the Collection field DelDateSort immediately after this action ?
    If it is, Reset the Gallery 
    Reset(GalleryName)
    at the end of the UpdateIf code.
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee
  • 55552 Profile Picture
    674 on at
    In response to TimL and WarrenBelz, thanks very much. I attempted TimL's suggestion of resetting the gallery (and it did appear that the DelDateSort column in the collection was being immediately updated), but this did not work.
     
    So I ended up adding a Select statement at the end of the OnChange code in the date picker control to Select the Project combo box at the top of the page. This essentially re-runs the code that gets data, filters and sorts the items for the gallery. I was trying to avoid that, thinking it would be slow or use un-necessary resources, but it does run fairly quickly and ensures re-sorting and pulling the most updated data.
     
    Thanks again for the thoughtful suggestions.
  • 55552 Profile Picture
    674 on at
    Question was answered, see below.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Kalathiya Profile Picture

Kalathiya 321 Super User 2026 Season 1

#2
WarrenBelz Profile Picture

WarrenBelz 289 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 200 Super User 2026 Season 1

Last 30 days Overall leaderboard