I've created a new screen and gallery in my app and am trying to sort the data shown in the gallery in ascending order. I've used "SortByColumns" extensively in my app and don't have trouble in any other form. But on this new form it looks like "If(SortDescending1, Ascending, Descending) " is not acceptable to the "SortByColumns" function.
This is what I'm trying to use:
If(ComboBox2.SearchText = "",
TruckStockInventoryDB,
SortByColumns(Filter(TruckStockInventoryDB, Title = First(ComboBox2.SelectedItems).Title Or Title = ComboBoxSearchText.Text), "Title", If(SortDescending1, Ascending, Descending)))
I've tried using just "Ascending", and while that does not produce an error it does not actually sort my gallery.
What am I missing?
Solved! Go to Solution.
@awalker ,
That was the problem in your original code as you had the search box text outside your Sort, but the code I gave you put it inside - just for a debugging exercise, try this
Sort(
If(
Len(ComboBox2.Selected.Title)=0,
TruckStockInventoryDB,
Filter(
TruckStockInventoryDB
Title = ComboBox2.Selected.Title
)
),
Title,
If(
SortDescending1,
Ascending,
Descending
)
)
Please click Accept as solution 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 Thumbs Up.
I found that I missed the sort button on the ribbon at the top of the screen that established the SortDescending1 variable.
I added the sort button and variable but and the error went away. However, the gallery is still not sorting.
I am not sure why the gallery won't sort at this point.
@awalker ,
If you put on the icon
UpdateContext({SortDescending1:!SortDescending1})
it will sort by your Title field - is this the field you want to sort on?
However looking further, it will only sort with something in your search box - try this
SortByColumns(
Filter(
TruckStockInventoryDB,
Len(ComboBox2.Selected.Title)=0 || Title = ComboBox2.Selected.Title
),
"Title",
If(
SortDescending1,
Ascending,
Descending
)
)
Please click Accept as solution 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 Thumbs Up.
Thank you for responding. Here is what I get when replacing my code with the one provided:
@awalker ,
Bracket in the wrong place - dangers of free-typing code - try it now.
Please click Accept as solution 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 Thumbs Up.
Oops. Ok, I tried it again:
The code has no error, but the gallery still only sorts in descending order.
Greetings
I should note that when I push the sort button UpdateContext({SortDescending1: !SortDescending1}), the list in Sharepoint sorts accordingly, but the gallery does not.
@awalker ,
What do you mean the list does and the gallery does not? I assumed the code is on the Items of the Gallery?
The code is on Items of the gallery. For some reason the sharepoint list will sort ascending and descending when I click the reorder button. But the gallery will stay the same.
Well, I promise it was resorting my sharepoint list earlier, but now I cannot repeat it. Neither the Sharepoint lists or gallery is resorting at this point.
User | Count |
---|---|
174 | |
115 | |
86 | |
44 | |
41 |
User | Count |
---|---|
238 | |
150 | |
132 | |
77 | |
73 |