Skip to main content

Notifications

Power Apps - Building Power Apps
Unanswered

Gallery does not re-sort after changing a date

(1) ShareShare
ReportReport
Posted on by 636
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?
  • 55552 Profile Picture
    55552 636 on at
    Gallery does not re-sort after changing a date
    Question was answered, see below.
  • 55552 Profile Picture
    55552 636 on at
    Gallery does not re-sort after changing a date
    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.
  • WarrenBelz Profile Picture
    WarrenBelz 144,858 on at
    Gallery does not re-sort after changing a date
    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
  • timl Profile Picture
    timl 33,150 on at
    Gallery does not re-sort after changing a date
     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.
  • 55552 Profile Picture
    55552 636 on at
    Gallery does not re-sort after changing a date
    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.
     
  • WarrenBelz Profile Picture
    WarrenBelz 144,858 on at
    Gallery does not re-sort after changing a date
    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.

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

Kickstarter Events…

Register for Microsoft Kickstarter Events…

Tuesday Tip #12 Start your Super User…

Welcome to a brand new series, Tuesday Tips…

Tuesday Tip #13 Writing Effective Answers…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 144,858

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,505

Leaderboard