Programmatic filtering

10 posts, 0 answers
  1. Vitaliy
    Vitaliy avatar
    10 posts
    Member since:
    Mar 2018

    Posted 22 Mar 2018 Link to this post

    Hi, I'm stuck with such a problem.

    I need to filter data at grid only from code (ShowFilteringRow = false). My filter condition is slightly complex so I use the FilterPredicate just like that - https://docs.telerik.com/devtools/winforms/gridview/filtering/custom-filtering#implementing-filtering-mechanism-using-filterpredicate

    I've set  EnableCustomFiltering = true and implement the PerformFiltering predicate:

    private void ChangeFilter(bool filtering)
    {
        tree.BeginEdit();
        if (filtering)
        {
            tree.MasterTemplate.FilterPredicate = new Predicate<GridViewRowInfo>(PerformFiltering);
        }
        else
        {
            tree.MasterTemplate.FilterPredicate = null;
        }
        tree.EndEdit();
    }
     
    private bool PerformFiltering(GridViewRowInfo row)
    {
        return (decimal)row.Cells["UnitPrice"].Value > 30;
    }

    But nothing happens when I fire the ChangeFilter() - the data still unfiltered. Do you know please, ehat am I doing wrong, or how can I fire filtering process from code?

    M

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3087 posts

    Posted 26 Mar 2018 Link to this post

    Hello, Vitaliy, 

    Following the provided information, I have prepared a sample project. It seems that the filtering works as expected on my end with a filter predicate. The attached gif file illustrates the behavior on my end? Am I missing something? I have attached my sample project. Could you please specify the exact steps how to reproduce the problem? Thank you in advance for your cooperation.

    I am looking forward to your reply.

    Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Vitaliy
    Vitaliy avatar
    10 posts
    Member since:
    Mar 2018

    Posted 26 Mar 2018 Link to this post

    Oh, that was EnableCustomFiltering as I see.

    There must be just EnableFiltering. Thank you!

  4. Vitaliy
    Vitaliy avatar
    10 posts
    Member since:
    Mar 2018

    Posted 28 Mar 2018 Link to this post

    I have one more question about code filtering. It's about perfomance.

    My situation here. I have two RadGridViews - 'categories' and 'content'. Both of them has self-refferenced data with automatic hierarchy generation. Besides this, the 'content' data refers to 'categories' by some dedicated id field.

    I load data to grids from IList<MyBusinessInterface> because of my application structure. Then I want 'content' grid to filter its data accordingly to the category, that is selected in 'categories' grid. I do this by SelectionChanged event of 'categories'.

    So, everything works correctly, BUT filter perfomance is weak. This is clearly shown, when you navigate thru 'categories' grid by keyboard - the 'content' grid is freezing. Time analizing told me, that grid's EndUpdate takes much time.

    Can you advice me, what I'm doing wrong in this case? Maybe there is another way to do that kind of programmatic filtering smooth? Thank you.

    I created test project to show you the problem. But I can't attach it directly, so there is a link - http://dropmefiles.com/dxlHH

    PS. I know, I can merge these two grids and create one grid with child template, but that's not suitable for our clients.
  5. Vitaliy
    Vitaliy avatar
    10 posts
    Member since:
    Mar 2018

    Posted 29 Mar 2018 Link to this post

    Well, I came up here.

    Bind filter predicate only one time in Form_Load. Then change the SelectionChanged event like this:

    private void gridCategories_SelectionChanged(object sender, EventArgs e)
    {
      //gridContent.BeginUpdate();
     
      // no selection - show all content
      if (gridCategories.SelectedRows.Count == 0)
      {
        doFilter = false;
      }
      // else show only the content, related to selected category
      else
      {
        selectedCategory = gridCategories.SelectedRows[0].DataBoundItem as ICategory;
        doFilter = true;
      }
     
      // change sorting to force the grid to update without calling EndUpdate
      // this will perform filtering with new params much more faster, then EndUpdate
      gridContent.Columns["Charcode"].Sort(RadSortOrder.None, false);
      gridContent.Columns["Charcode"].Sort(RadSortOrder.Ascending, false);
     
      //gridContent.EndUpdate();
    }
     
    // PS. selectedCategory and doFilter are the row filtering params

    This works perfect, much faster, then EndUpdate. But looks some ugly) Do you know, please, a better way to update filtering without EndUpdate?

  6. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3087 posts

    Posted 29 Mar 2018 Link to this post

    Hello, Vitaliy,  

    The provided sample project is greatly appreciated. Using Begin/EndUpdate block is appropriate for improving performance when you need to perform operations that affect the UI. I have tested with the latest version and the performance seems to be OK on my end. When I select a new category from the left grid, the right one is filtered immediately. Please refer to the attached gif file. Am I missing something? Could you please specify the exact steps how to reproduce the problem? A sample video illustrating the performance problem on your end would be also very useful. You can use Jing (a free tool) for capturing the video. Thank you in advance for your cooperation.

    I am looking forward to your reply.

     Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  7. Vitaliy
    Vitaliy avatar
    10 posts
    Member since:
    Mar 2018

    Posted 29 Mar 2018 Link to this post

    Well, I've recorded some video. External link again, cause it exceeds max. file size for the forum :)

    Note, that left grid selection coming not in time after the cursor clicking.
    Because of filtering right grid in left SelectionChanged

  8. Vitaliy
    Vitaliy avatar
    10 posts
    Member since:
    Mar 2018

    Posted 29 Mar 2018 Link to this post

    PS. Also, in real project I may have more content rows at each category - some hundreds. I have even a bigger time lag then.

    I'm running a DevCraftUltimate free trial on VS 2013 now, if this matters.

  9. Vitaliy
    Vitaliy avatar
    10 posts
    Member since:
    Mar 2018

    Posted 29 Mar 2018 Link to this post

    I've measured time:
    2 categories and 5000 content items - it takes 17 seconds for one filtering operation. This is huge.

    Then I've managed to make some 'manual' filtering like that:

            private void ManualFiltering()
            {
                bool visible;
                foreach (var item in gridContent.Rows)
                {
                    if (item.HierarchyLevel != 0)
                        continue;
                    visible = FilterRow(item);
                    item.IsVisible = visible;
                    FilterChildren(item, visible);
                }
            }

            private void FilterChildren(GridViewRowInfo row, bool visible)
            {
                foreach (var item in row.ChildRows)
                {
                    item.IsVisible = visible;
                    FilterChildren(item, visible);
                }
            }

    FilterRow - is my old filter predicate. And it works like a superjet! Just 0.1 sec to filtering 5000 content items instead of 17 secs! 
    So, I gess Begin/EndUpdate block performs many operations, unnesessary for filtering (maybe it rebinds auto-hierarchy). It would be great to obtain a single RadGridView method like a 'Filter()' to perform only UI changes, that really need for filtering.

    Then I could use it after changing outer filter condition :)

     

  10. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3087 posts

    Posted 02 Apr 2018 Link to this post

    Hello, Vitaliy,   

    Calling BeingUpdate/EndUpdate methods will refresh the UI only once. It is usually used for optimizing performance when you perform an operation a lot of times that affects the visual row elements. If the filter row works good for your case, I can suggest you to add a FilterDescriptor programmatically. Thus, RadGridView will filter the rows considering the property name and value of the FilterDescriptor. Additional information about this type of filtering is available here: https://docs.telerik.com/devtools/winforms/gridview/filtering/setting-filters-programmatically-(simple-descriptors)

    I hope this information helps. If you have any additional questions, please let me know. 

    Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top