GridView filtering combined with custom groupcomarer

1 Answer 96 Views
GridView GroupBox
Daniel
Top achievements
Rank 2
Iron
Iron
Daniel asked on 20 Apr 2023, 12:41 PM

Hi Telerik supportteam,

I’ve found something interesting around filtering combined with a CustomGroupComparer on a RadGridView. To illustrate the situation I added a small example application.

 

Situation:

Start the application, create a groupBy on e.g. TwoStateCheckbox column, expand some of the groups.

Now, filter on e.g. Name (contains ‘7’).

 

Result:

All the groups get collapsed.

 

My own analyses:

With a breakpoint on rule 21 in the CustomGroupComparer, I see that dataGroup.IsExpanded is false, even when the group in the grid is expanded.

With a custom group comparer, Telerik does something with a groupBuilder. It suggests that groups are cloned? If that’s the case I guess the IsExpanded property is not set correctly. Sounds like a bug to me. Can you confirm this and how can I work around this??

 

By the way: without a customGroupComparer it works ok but we need the custom thing.

Regard,

Daniel Kaya

1 Answer, 1 is accepted

Sort by
0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 21 Apr 2023, 02:34 PM

Hi Daniel,

Using the provided project I was able to reproduce this behavior. It turns out that this behavior is already logged in our Feedback Portal. At that time it was logged when sorting the grid. In your case, filtering the grid will also collapse the expanded groups. I have updated the item to also include filtering. I have increased the priority of the item so that our development team could consider planning this for fixing in one of our next releases.

In the meantime, what I can suggest as a workaround is to manually expand the groups after filtering. You will need to preserve the expanded group and after the filter is applied you can expand them again. You can subscribe to the FilterChanging and FilterChanged events of the control.

private Dictionary<string, bool> groupsCache = new Dictionary<string, bool>();
private void RadGridView1_FilterChanging(object sender, GridViewCollectionChangingEventArgs e)
{
    foreach (DataGroup group in this.radGridView1.Groups)
    {
        groupsCache[group.Header] = group.IsExpanded;
    }
}

private void RadGridView1_FilterChanged(object sender, GridViewCollectionChangedEventArgs e)
{
    foreach (DataGroup group in this.radGridView1.Groups)
    {
        if (this.groupsCache.ContainsKey(group.Header))
        {
            if (this.groupsCache[group.Header])
            {
                group.Expand();
            }
            else
            {
                group.Collapse();
            }
        }
    }
}

I have also modified the project with the above approach. So far my tests show that it is working as expected. Give it a try and let me know if I have missed a scenario.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Daniel
Top achievements
Rank 2
Iron
Iron
commented on 24 Apr 2023, 01:43 PM

Hi Dinko,

Thanks for your reaction. I've changed my code with your example and it works for filtering. Also implemented it for sorting. I encountered one more scenario. Don't know if this is the same bug but let me explain it in the example project..

Set a group by on TwoStateCheckbox, expand the two groups and then press 'Button 3'. This button add's a new record. The group in which the new records gets placed, is like expected still exapanded. The other one gets collapsed.

Is this the same issue??

Daniel

 

Dinko | Tech Support Engineer
Telerik team
commented on 25 Apr 2023, 07:19 AM

It seems that this behavior is also related to the above one. I have updated the internal item so that our developers will take it into account. What I can suggest as a workaround is similar to the above one. Before adding the new row, you can cache the expanded groups. After adding the row, you can expand them. Keep in mind that expanding the groups will move the scroll from the added row and it will go outside of the viewport. You can use ScrollToRow() method to scroll to the last added row.

private void button3_Click(object sender, EventArgs e)
{
    foreach (DataGroup group in this.radGridView1.Groups)
    {
        groupsCache[group.Header] = group.IsExpanded;
    }

    _dataSource.Add(new Person("testje 1234", true, false, Painted.No));

    foreach (DataGroup group in this.radGridView1.Groups)
    {
        if (this.groupsCache.ContainsKey(group.Header))
        {
            if (this.groupsCache[group.Header])
            {
                group.Expand();
            }
            else
            {
                group.Collapse();
            }
        }
    }
    this.radGridView1.TableElement.ScrollToRow(this.radGridView1.Rows.Last());
}

 

Tags
GridView GroupBox
Asked by
Daniel
Top achievements
Rank 2
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or