nyna77
Topic Author
Posts: 1
Joined: 30 Jun 2017, 12:02

Data sorting with columns in Unity

31 Jul 2018, 16:30

Hi,
I'm trying to make table with data that can be filtered and sorted by some values. I ended up with ListView and GridView as View for that List. To allow user to sort rows by values in columns I added ColumHeader with call to appropriate method in CodeBehind. It's works pretty good in Visual Studio as XAML project. XAML code below.
<ListView Grid.ColumnSpan="5" Grid.Row="2" ItemsSource="{Binding FilteredApartament}">
                <ListView.View>
                    <GridView AllowsColumnReorder="False">
                        <GridViewColumn DisplayMemberBinding="{Binding Path=ID}" Width="100">
                            <GridViewColumnHeader Content="ID" Click="Sort" />
                        </GridViewColumn>
                        <GridViewColumn DisplayMemberBinding="{Binding Path=Floor}" Width="100">
                            <GridViewColumnHeader Content="Floor" Click="Sort" />
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
            </ListView>
But when I tried to run it in Unity I met same complications.
1.
protected override bool ConnectEvent(object source, string eventName, string handlerName)
        {
            if (eventName == "Click" && handlerName == "Sort")
            {
                ((GridViewColumnHeader)source).Click += this.Sort;
                return true;
            }
            return false;
        }
Code above subscribe event but don't call assigned method on actually click. Is it my miss understand of this system or bug?

2. I worked around above with:
protected override bool ConnectEvent(object source, string eventName, string handlerName)
        {
            if (eventName == "Click" && handlerName == "Sort")
            {
                var g = (GridViewColumnHeader)source;
                g.MouseDown += this.Sort;
                g.Click += this.Sort;
                return true;
            }

            return false;
        }
but then in my sorting method after cast sender to GridViewColumnHeader the Column property is null. I need this for:
columnHeaderClicked.Column.HeaderTemplate = direction == SortState.Ascending ?
                Resources["HeaderTemplateArrowUp"] as DataTemplate :
                Resources["HeaderTemplateArrowDown"] as DataTemplate;
Are those knows issues? Is there any better way to do that?

TIA

Tags:
 
User avatar
sfernandez
Site Admin
Posts: 1785
Joined: 22 Dec 2011, 19:20

Re: Data sorting with columns in Unity

01 Aug 2018, 13:58

Hi,

I reviewed the code and found we have a bug there. Because we are always creating a GridViewColumnHeader instance to use as Content what is defined in GridViewColumn.Header. So what is happening is that Click is raised for that internally generated object instead of the one defined in xaml.

Could you please report this in our bugtracker so we can keep track of the problem, thanks.

Meanwhile the solution will be quite tricky, because you would need to search (on the Loaded event) for the GridViewHeaderRowPresenter inside the ListView template, and get the generated GridViewColumnHeader by iterating its visual children. Then you can attach the Click handler to the correct headers. Let me know if you need help with that.
 
wyvern010
Posts: 24
Joined: 18 Apr 2019, 13:41

Re: Data sorting with columns in Unity

18 Jun 2019, 15:20

Hi i can also confirm this bug inside C# (No Unity)
Click action will bind but not be called.
MouseLeftButtonDown does in fact get called, but Column property is empty.
 
User avatar
sfernandez
Site Admin
Posts: 1785
Joined: 22 Dec 2011, 19:20

Re: Data sorting with columns in Unity

19 Jun 2019, 19:40

I created a ticket to follow the resolution of this bug: https://www.noesisengine.com/bugs/view.php?id=1499

Who is online

Users browsing this forum: Bing [Bot] and 2 guests