Skip to content
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

CollectionView with grouping enabled doesn't reflect the change on UI when a child record is added/removed #22158

Open
boopathyraj25 opened this issue May 1, 2024 · 11 comments
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@boopathyraj25
Copy link

boopathyraj25 commented May 1, 2024

Description

CollectionView with grouping enabled doesn't reflect the change on UI when a child record is removed

Steps to Reproduce

  1. Run the code from repo link provided below which will preload parent and child records on the collectionview.
  2. Tap on a child item to remove it from collection. The item is programmatically removed but not reflected on the UI.
  3. Click on "+" against any parent item to add a new child record which is pragmatically added but not reflecting on the UI

Link to public reproduction project repository

https://github.com/boopathyraj25/MAUI.CollectionViewBugs

Version with bug

8.0.14 SR3.1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 27 and up

Did you find any workaround?

No

Relevant log output

No response

@boopathyraj25 boopathyraj25 added the t/bug Something isn't working label May 1, 2024
@Eilon Eilon added the area-controls-collectionview CollectionView, CarouselView, IndicatorView label May 1, 2024
@PureWeen
Copy link
Member

PureWeen commented May 2, 2024

/similarissues

Copy link
Contributor

github-actions bot commented May 2, 2024

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@boopathyraj25 boopathyraj25 changed the title CollectionView with grouping enabled doesn't reflect the change on UI when a child record is removed CollectionView with grouping enabled doesn't reflect the change on UI when a child record is added/removed May 3, 2024
@RoiChen001 RoiChen001 added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels May 6, 2024
@RoiChen001
Copy link

Can repro this issue at Android platform on the latest 17.10 Preview 6(8.0.21).

@gework7
Copy link

gework7 commented May 16, 2024

First of all, I'd recommend checking the documentation for properly structuring the data into groups before binding it to the CollectionView. When I encountered a similar issue before, the key solution for me was to use ObservableCollection instead of List for the elements.

ObservableCollection provides notifications when items are added, removed, or changed, ensuring that the UI stays in sync with the underlying data.

Define a model class for the service category group:

public class ServiceCatGroup : ObservableCollection<ServiceUIModel>
{
    public string CategoryName { get; private set; }

    public ServiceCatGroup(string categoryName, ObservableCollection<ServiceUIModel> services) : base(services)
    {
        CategoryName = categoryName;
    }
}

@boopathyraj25
Copy link
Author

First of all, I'd recommend checking the documentation for properly structuring the data into groups before binding it to the CollectionView. When I encountered a similar issue before, the key solution for me was to use ObservableCollection instead of List for the elements.

ObservableCollection provides notifications when items are added, removed, or changed, ensuring that the UI stays in sync with the underlying data.

Define a model class for the service category group:

public class ServiceCatGroup : ObservableCollection<ServiceUIModel>
{
    public string CategoryName { get; private set; }

    public ServiceCatGroup(string categoryName, ObservableCollection<ServiceUIModel> services) : base(services)
    {
        CategoryName = categoryName;
    }
}

@gework7 , I will definitely try this. Thank you. BTW I don't see Observable collection mentioned in the documentation instead List is used.

@gework7
Copy link

gework7 commented May 31, 2024

@boopathyraj25 did it work?

@boopathyraj25
Copy link
Author

boopathyraj25 commented May 31, 2024

@boopathyraj25 did it work?

@gework7
It works but it's not a solution for my use case because my requirement is to have the CategoryName as well an Observable property. In order to achieve that I had to annotate the class with [ObservableObject] which doesn't allow inheriting ObservableCollection but it works with List.

@jsuarezruiz jsuarezruiz added this to the Backlog milestone Jun 5, 2024
@jari-schuurman
Copy link

@boopathyraj25 did it work?

@gework7 It works but it's not a solution for my use case because my requirement is to have the CategoryName as well an Observable property. In order to achieve that I had to annotate the class with [ObservableObject] which doesn't allow inheriting ObservableCollection but it works with List.

The observable collection already implements the necessary INotifyPropertyChanged interfaces. Just make a private field categoryName and public property CategoryName, then in the setter call On property changed(new(name of(CategoryName));

private string categoryName;

public string CategoryName
{
    get => categoryName;
    set {
        categoryName = value; 
        OnPropertyChanged(new(nameof(CategoryName));
    }
}

@boopathyraj25
Copy link
Author

@jari-schuurman ,
It worked. Thank you very much for the solution.

@jari-schuurman
Copy link

@boopathyraj25 just be aware of a memory leak, more details can be found here: #22954

@boopathyraj25
Copy link
Author

boopathyraj25 commented Jun 11, 2024 via email

@samhouts samhouts removed s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 3, 2024
@samhouts samhouts added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants