Completed
Last Updated: 22 Dec 2017 11:43 by ADMIN
ADMIN
Hristo
Created on: 12 Jul 2017 09:14
Category: GridView
Type: Bug Report
1
FIX. RadGridView - setting the BypassSort property to true disables filtering in the grid
How to reproduce:
public partial class Form1 : Form
{
    private DataTable dt = new DataTable();

    public Form1()
    {
        InitializeComponent();

        this.FillData();

        this.radGridView1.DataSource = this.dt;
        this.radGridView1.EnableSorting = true;
        this.radGridView1.EnableFiltering = true;

        this.radGridView1.MasterTemplate.DataView.BypassSort = true;
        this.radGridView1.SortChanged += radGridView1_SortChanged;
        this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
    }

    public void FillData()
    {
        dt.Columns.Add("Id", typeof(int));
        dt.Columns.Add("Name", typeof(string));

        for (int i = 0; i < 30; i++)
        {
            dt.Rows.Add(i, "Item" + i);
        }
    }

    private void radGridView1_SortChanged(object sender, Telerik.WinControls.UI.GridViewCollectionChangedEventArgs e)
    {
        if (e.Action == NotifyCollectionChangedAction.Add || e.Action == NotifyCollectionChangedAction.ItemChanged)
        {
            SortDescriptor s = e.NewItems[0] as SortDescriptor;
            string sortOperator = "";
            if (s.Direction == ListSortDirection.Ascending)
            {
                sortOperator = "ASC";
            }
            else
            {
                sortOperator = "DESC";
            }
            dt.DefaultView.Sort = s.PropertyName + " " + sortOperator;
        }
        if (e.Action == NotifyCollectionChangedAction.Remove)
        {
            dt.DefaultView.Sort = "";
        }
    }
}

Workaround: 
public partial class Form1 : Form
{
    private DataTable dt = new DataTable();

    public Form1()
    {
        InitializeComponent();

        this.FillData();

        this.radGridView1.DataSource = this.dt;
        this.radGridView1.EnableSorting = true;
        this.radGridView1.EnableFiltering = true;

        this.radGridView1.MasterTemplate.DataView.BypassSort = true;
        this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;

        this.radGridView1.CellBeginEdit += RadGridView1_CellBeginEdit;
        this.radGridView1.CellEndEdit += RadGridView1_CellEndEdit;
    }

    private void RadGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
    {
        if (e.Row is GridViewFilteringRowInfo)
        {
            this.radGridView1.MasterTemplate.DataView.BypassSort = true;
        }
    }

    private void RadGridView1_CellBeginEdit(object sender, Telerik.WinControls.UI.GridViewCellCancelEventArgs e)
    {
        if (e.Row is GridViewFilteringRowInfo)
        {
            this.radGridView1.MasterTemplate.DataView.BypassSort = false;
        }
    }
    public void FillData()
    {
        dt.Columns.Add("Id", typeof(int));
        dt.Columns.Add("Name", typeof(string));

        for (int i = 0; i < 30; i++)
        {
            dt.Rows.Add(i, "Item" + i);
        }
    }
}
6 comments
ADMIN
Hristo
Posted on: 17 Aug 2017 08:30
Hello Philip,

Currently we are not aware of performance issues while filtering or sorting the grid. The purpose of the BypassSort and BypassFilter properties is to provide means for applying the filter or the sorting to the underlying data source object rather than to the grid. The feedback item clearly states what is the nature of the issue and it is that setting the BypassSort property to true disables filtering in the grid. Since you are having performance issues you will need to open a support ticket in which you can attach your project and details about your local set-up. This way we would be able to investigate it. 

Regards,
Hristo 
Phillip
Posted on: 16 Aug 2017 12:33
Fix makes little or no difference.
On a dataset of 200 records, getting rid of a filter word (four characters) takes:
No Sorting, No Grouping: .001seconds
Sorting, No Grouping: 13seconds
No Sorting, Grouping: .5 seconds
Sorting and Grouping: 13seconds

As mentioned earlier, I still don't understand why Grouping, which surely has to put the records in order (i.e. sorted) is super quick.
Has it ever been investigated or is the "do it yourself" argument used instead? 
TIA
Phillip
Posted on: 16 Aug 2017 12:06
Two further questions:
1) if we need to handle the filtering ourselves, why exactly are we paying for controls again?
2) back on the sorting performance issue that starts this whole thing in the first place. Why is sorting so slow but grouping of same dataset super quick? Why isn't the same algorithm/process used? 
Will test out the workaround and see if it helps.
By the way, when you say large amount of data, we are talking about 600 rows maximum! Did you test out the difference on getting rid of a filter when there is a sort on and when there is no sorting? 
ADMIN
Hristo
Posted on: 16 Aug 2017 11:37
Hello Philip,

A workaround other than setting the BypassSort property to false would not be possible. Indeed setting the value in the FilterChanged and CollectionChanged event will be executed on every key press. A similar workaround can be implemented in the CellBeginEdit and CellEndEdit events causing the BypassSort property to be set only once. I have changed the code snippet above to demonstrate this. In case you need further assistance please use your Telerik Account to open up a support ticket so that we can investigate your actual setup.

Since you are actually having large amounts of data and you are already sorting the grid manually, you can also consider setting the BypassFilter property to true and not use the workaround. This way you will be solely responsible to handle filtering and sorting. An example is available here: http://docs.telerik.com/devtools/winforms/gridview/filtering/basic-filtering.

Hristo
Phillip
Posted on: 14 Aug 2017 15:09
Just further to the last comment, was able to prove (at least to me) its the reintroduction of the Sorting Performance issue via removing a filtered word. I.E. if you filter by the word "goods" and then select that word and remove it, if you have no sorted rows, the filtering goes from changing event to changed event almost instantly. If there is a column sorted, it is extremely slow.
Phillip
Posted on: 03 Aug 2017 23:16
We have tried this workaround but in our testing with our application and dataset we see that the filtering is extremely slow. When I say slow, each letter takes multiple seconds to a minutes to show depending on if there is a column that we have already sorted on. Is there any plans to fix the underlying bug as gut feel is that by turning off the sorting bypass, you reintroduce the sorting performance issue.
Any thoughts welcomed.