New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Order groups by #58
Comments
A minute later I find the |
Actually, it's not the perfect solution. I'd like to know what you think about the feature! |
Hi @xJon, currently there is no custom sorting option available. The groups and the elements inside each group are sorted according their comparable implementation. So for example when using Dates the groups will be sorted by date and not alphabetically. The groupHeaderBuilder could then display the weekday or something. What is your groupBy value? Will this solution work for you? A solution which was discussed before is to add an sortBy option, which returns for two group a Int value defining the order. So basically the like comparable Interface with the only difference that with this solution a separate sorting for the list can be done. Let me know what you think. |
Hi, thank you for the quick and detailed response. |
@xJon I mean't that you can do something like this: groupBy: (element) => DateFormat('yyyy-MM-dd').format(element.date),
groupHeaderBuilder: (Element element) => Text(
'${DateFormat.yMMMd().format(element.date)}',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
), The List is grouped by the actual date (without time) and then in As you can see the months are displayed and in chronological order and not in alphabetical order. |
I see. That is a useful option but it isn't applicable in my case, as I am trying to use |
@xJon No problem, what exactly want you to do? GroupedList<Element, Group> (
groupBy: (element) => element.groupByValue
[...]
),
[...]
class Group implements Comparable {
var sortValue;
[...]
@override
int compareTo(other) {
return sortValue.compareTo(other.sortValue);
}
} As you can see the list is grouped by a field of the element. This field's class implements the Comparable interface. There a custom comparison is implemented. |
I came here because of the same issue. The idea would be OK but it seems the execution is not yet perfect. :-) Even if I have |
Indeed. If I create a little helper:
And use it in both places where you directly compare |
Since the procedure seems a little confusing I thought of a solution and is my proposal: A new option GroupedList<Element, Group> (
groupBy: (element) => element.groupByValue
sortGroupBy: (group1, group2) => [..] // needs to return an int in range [-1, 1] (same as `compareTo`).
[...]
), @deakjahn, @xJon What do you think, would that solve your problem? |
Fine. I would actually suggest this over the |
To be clear here, the new option will only be used for sorting. So with that new option you must not implement and override the If you want two groups to be treated as the same the only way is and will be that they are equal in terms of the == Operator. In my eyes there is no need to change that. |
Yes, confirmed, it works that way. If you just mention this in the source comments around |
Closed with #59 |
Hi @Dimibe, thank you for the new feature! |
@xJon No that's not possible because it is not known what item is "first" during sorting. This information is obviously only accessible after the list is sorted once. So the list would have to be sorted twice. What you could do is to store the "timestamps" of each group manually (e.g. in a map) and then access them in the groupComparator function. |
@Dimibe Looks like a good solution, thank you. |
@Dimibe I got it to work exactly as wanted with your advice! |
@xJon and @Dimibe Sorry to bring you back to this issue but I am in a very similar pickle to this. I have the items grouped and all that I am fetching from firestore. Or maybe @xJon you would be so kind as to offer some detail into the solution you used to got this working The image below can give you a clue of what I am facing. My groupBy argument:
With the basic logic being
Inside my group separator builder, I have several conditionals similar to this:
I hope you can guide me on the missing step. Thanks |
Hi, first of all thank you for creating a great & useful package.
I wanted to ask - is there a way to order the groups by a custom (and not alphabetical) order?
Thank you!
The text was updated successfully, but these errors were encountered: