Giter VIP home page Giter VIP logo

Comments (7)

 avatar commented on May 19, 2024

Hello Hot-Gun, thank you for your interest in Windows Community Toolkit!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible.. Other community members may also answer the question and provide feedback 🙌

from dotnet.

Kyaa-dost avatar Kyaa-dost commented on May 19, 2024

@Hot-Gun Thanks for highlighting the issue but it does seem like that the only letters that are triggered to be added at end of the list (not in alphabetical) are not part of the existing Items list. I am not certain if it's intended by design. I will tag this and see if community members can provide further insight.

Attached is the video of the sample

V4cURZqsne_Trim.mp4

from dotnet.

michael-hawker avatar michael-hawker commented on May 19, 2024

FYI @vgromfeld @Sergio0694 who have knowledge in this space.

But Add will always add to the end of a collection, there should be an InsertItem method you can call as well.

You'd have to figure out where you need to insert the item into your collection I believe, otherwise the sorting part should be handled by the CollectionViewSource?

from dotnet.

Hot-Gun avatar Hot-Gun commented on May 19, 2024

So, @Sergio0694 didn't help me. But I found a solution. Maybe someone will show a more elegant option, but here's what I replaced, based on an example from the WindowsCommunityToolkit:
I will do tests in the future to make sure that this is not causing the problem.
Original from example:

        var groupName = GetGroupName(newContact);
        var targetGroup = _contactsSource.FirstOrDefault(group => group.Key == groupName);
        if (targetGroup is null)
        {
            _contactsSource.Add(new ObservableGroup<string, Person>(groupName, new[] { newContact }));
        }
        else
        {
            targetGroup.Add(newContact);
        }

My code:

        var groupName = GetGroupName(newContact);
        var targetGroup = _contactsSource.FirstOrDefault(group => group.Key == groupName);
        if (targetGroup is null)
        {
                List<string> tempList = _contactsSource.ToDictionary(x => x.Key).Keys.ToList();
                tempList.Add(groupName);
                tempList.Sort();
                _contactsSource.Insert(tempList.IndexOf(groupName), new ObservableGroup<string, Person>(groupName, new[] { newContact }));
        }
        else
        {
                List<Person> tempList = targetGroup.ToList();
                tempList.Add(newContact);
                var query = tempList.OrderBy(x => x.Name);
                tempList = query.ToList();
                targetGroup.Insert(tempList.IndexOf(newContact), newContact);
        }

from dotnet.

vgromfeld avatar vgromfeld commented on May 19, 2024

@Hot-Gun, the sample page is very basic. It only uses Add() because it was simpler to showcase the behavior of the ObservableGroupedCollection<TKey, TValue>.
Since it mostly just wraps an ObservableCollection<T>, it is up to you to insert the data where you want using InsertItem as @michael-hawker said.

You can simplify your code by doing a binary search in the groups list or the existing group content to find the insertion index.
Sadly, ObservableCollection<T> does not have it implemented but you can easily add your own.
This will improve the performances.

from dotnet.

michael-hawker avatar michael-hawker commented on May 19, 2024

@Hot-Gun this should ideally be supported by the CollectionViewSource helpers, we have some in the Toolkit, but not one that supports sorting and grouping. I've opened this WinUI issue on the topic please up-vote that one.

Though there is certainly room to improve our sample here as well.

from dotnet.

Sergio0694 avatar Sergio0694 commented on May 19, 2024

Closing this, as #168 did add new APIs to insert items in the right (sorted) position 🙂

from dotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.