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

Filtering of DataGrid bound to ObservableCollection #15728

Open
Big-Iron-Cheems opened this issue May 14, 2024 · 2 comments
Open

Filtering of DataGrid bound to ObservableCollection #15728

Big-Iron-Cheems opened this issue May 14, 2024 · 2 comments

Comments

@Big-Iron-Cheems
Copy link

Big-Iron-Cheems commented May 14, 2024

Describe the bug

I have a DataGrid as follows:

<DataGrid ItemsSource="{Binding FilteredModList}"> ... </DataGrid>

It is then bound to an ObservableCollection that I filter via the following binding:

<TextBox Margin="10" Text="{Binding SearchText}" />

In the debugger, stepping through my filter function, I can see that it has the intended amount of elements, yet the view does not render the correct amount.

To Reproduce

Create a DataGrid bound to an ObservableCollection, apply a filter operation on said list, see the view not updating the rows correctly.

Expected behavior

The DataGrid should respond correctly to filters/insertions on said list, and show the correct amount of rows.

Avalonia version

11.0.10

OS

Linux

Additional context

Code related to said DataGrid:
image

Example of list not returning to original state:
https://github.com/AvaloniaUI/Avalonia/assets/52252627/19e46003-88aa-4c74-b685-c401f28e9300

For further context: I implemented the same mechanic using ItemsControl and ItemsControl.ItemTemplate and executed the program (keeping the DataGrid impl for double checking) and in that case only the ItemsControl impl responds as intended.

@maxkatz6
Copy link
Member

Ideally, you shouldn't recreate input collection, but instead modify it. Removing filtered out items, adding new items. Or at least a combination of Clear+AddRange. "Observable" part of the ObservableCollection isn't utilized in your code.
DynamicData library can also help with filtering scenario.

But other than that, your code should also work, seems like a bug.

@Big-Iron-Cheems
Copy link
Author

Thanks for the response, I'll try using the DynamicData lib as you suggested, total newbie here.
Hopefully this gets addressed and fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants