WindowsCommunityToolkit icon indicating copy to clipboard operation
WindowsCommunityToolkit copied to clipboard

AdvancedCollectionView insert at bad index

Open texaclou opened this issue 2 years ago • 12 comments

Describe the bug

Hello, this is my first issue here, I hope I dot it the right way.

With a AdvancedCollectionView used with a Filter and without SortDescription, When a add a item to the source collection, the item is not inserted at the end of the CollectionView, it inserted before the last item.

With no filter there is no problem

Steps to reproduce

ObservableCollection<int> sourceList = new ()
 {
       1,2,3,4,5
 };

AdvancedCollectionView acv = new(sourceList, false);

//filter to keep only even integers
acv.Filter = x => (int)x % 2 == 0;
            
Assert.AreEqual("24", String.Join("", acv));
// succeed

sourceList.Add(6);

Assert.AreEqual("246", String.Join("", acv)); 
//failed  result = 264

Expected behavior

The new item should be inserted at the end

Windows Build Number

  • [ ] Windows 10 1809 (Build 17763)
  • [ ] Windows 10 1903 (Build 18362)
  • [ ] Windows 10 1909 (Build 18363)
  • [ ] Windows 10 2004 (Build 19041)
  • [ ] Windows 10 20H2 (Build 19042)
  • [X] Windows 10 21H1 (Build 19043)
  • [ ] Windows 11 21H2 (Build 22000)
  • [ ] Other (specify)

Windows Community Toolkit version

7.1.0

Visual Studio Version

2022

Device form factor

Desktop

Additional context

If there is no filter the insertion index is defined like this, so in this case it work correctly : https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/b21dbe71f64e86ca9bb0ba6cfb4cb4d20e93765a/Microsoft.Toolkit.Uwp.UI/AdvancedCollectionView/AdvancedCollectionView.cs#L661

I think the issue is from this line, in the HandleItemAdded method, when there is a filter the new item index is define like this : https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/b21dbe71f64e86ca9bb0ba6cfb4cb4d20e93765a/Microsoft.Toolkit.Uwp.UI/AdvancedCollectionView/AdvancedCollectionView.cs#L686

Help us help you

Yes, but only if others can assist.

texaclou avatar Jan 21 '22 17:01 texaclou

Hello texaclou, thank you for opening an issue with us!

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 look into the issue and provide feedback 🙌

ghost avatar Jan 21 '22 17:01 ghost

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

ghost avatar Feb 05 '22 19:02 ghost

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

ghost avatar Feb 20 '22 19:02 ghost

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

ghost avatar Mar 07 '22 19:03 ghost

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

ghost avatar Mar 22 '22 22:03 ghost

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

ghost avatar Apr 10 '22 10:04 ghost

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

ghost avatar Apr 25 '22 10:04 ghost

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

ghost avatar May 10 '22 13:05 ghost

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

ghost avatar May 25 '22 16:05 ghost

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

ghost avatar Jun 09 '22 16:06 ghost

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

ghost avatar Jun 24 '22 16:06 ghost

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

ghost avatar Jul 09 '22 19:07 ghost