Saving/loading filter settings

20 posts, 2 answers
  1. Finn
    Finn avatar
    27 posts
    Member since:
    Jun 2008

    Posted 21 Jul 2008 Link to this post

    RadGridView.MasterGridViewTemplate.Filter.ToString()
    easily gives me the current filter(s) .

    Would be real nice if there were a just as easy way to set (restore) filter(s).

    I still haven't figured out how to set the filters.
    I guess I'll have to start with
    Dim item As New Telerik.WinControls.Data.FilterExpression
    RadGridView.MasterGridViewTemplate.FilterExpressions.Clear()
    ... not sure how to parse the string I got above and how to build it into item
    RadGridView.MasterGridViewTemplate.FilterExpressions.Add(item)

     

     

  2. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 24 Jul 2008 Link to this post

    Hello Finn,

    Thank you for writing.

    Currently, RadGridView does not support save/load for filters. However, we find the request interesting and if other customers require it we will consider adding it in some of the future releases.

    If you have other questions, do not hesitate to contact me again.

    Sincerely yours,
    Martin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Finn
    Finn avatar
    27 posts
    Member since:
    Jun 2008

    Posted 25 Jul 2008 Link to this post

    OK, do you have any VB code snippets that shows how to save and (more importantly) restore a filter after a grid has been reloaded with data from database?
  4. Answer
    Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 28 Jul 2008 Link to this post

    Hi Finn,

    Thank you for getting back to me.

    As I have mentioned in previous post, RadGridView does not support Save/Load for its filters.
    Scenario realization is related to making a deep copy of FilterExpressions collections, because it is a reference type and if the filtering changes it changes all references too. Still, when you reload RadGridView data, you  could restore the last filter by using FilterExpression array field. Please, review a sample implementation of Save and Load function below:
    Private Function SaveFilter(ByVal grid As RadGridView) As FilterExpression() 
        Dim feCollection As FilterExpression() = New FilterExpression(grid.MasterGridViewTemplate.FilterExpressions.Count) {} 
     
        Dim i As Integer = 0 
        While i < grid.MasterGridViewTemplate.FilterExpressions.Count 
            feCollection(i) = grid.MasterGridViewTemplate.FilterExpressions(i) 
            System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1) 
        End While 
     
        Return feCollection 
    End Function 
     
    Private Sub LoadFilter(ByVal grid As RadGridView, ByVal filterExpressions As FilterExpression()) 
        grid.MasterGridViewTemplate.FilterExpressions.Clear() 
        For Each fe As FilterExpression In filterExpressions 
            grid.Columns(fe.FieldName).Filter = fe 
        Next 
    End Sub 

    I hope this helps, if you have other questions, do not hesitate to contact me again.

    Greetings,
    Martin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Finn
    Finn avatar
    27 posts
    Member since:
    Jun 2008

    Posted 28 Jul 2008 Link to this post

    Thank you Martin.

    Just what I needed!

    Finn
  6. Finn
    Finn avatar
    27 posts
    Member since:
    Jun 2008

    Posted 28 Jul 2008 Link to this post

    Oh, one question:
    Why this:
           System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1) 
     
    and not just i = i + 1?

    Finn
  7. Answer
    Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 29 Jul 2008 Link to this post

    Hello Finn,

    Thank you for the question.

    Because in my development I use C#, and then convert the code with a converter tool (http://converter.telerik.com), I didn't notice this line.

    It is correct, but please feel free to change this loop statement according to best VB practices.

    If you need additional assistance, do not hesitate to contact me again.

    Best wishes,
    Martin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. Mike
    Mike avatar
    338 posts
    Member since:
    Jun 2008

    Posted 31 Jul 2008 Link to this post

    supposedly you can save your settings using this class, I am trying it now.  Hopefully they have a better example of how I reference this class in my code behind which binds the grid.

    Saving grid settings
    http://www.telerik.com/help/aspnet-ajax/grdsavingsettingsonperuserbasis.html

  9. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 01 Aug 2008 Link to this post

    Hi George,

    Thank you for sharing your investigations.

    Actually, you could not apply the same solution as for the ASP RadGrid because the FilterExpressions class is not serializable. This makes the implementation of such scenario not very easy task, because you have to implement your own deep copy (or serialize) method for FilterExpression. Nevertheless, we will consider adding such functionality in a future version of RadGridView

    If you have other questions, do not hesitate to contact me again.

    Best wishes,
    Martin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  10. Mike
    Mike avatar
    338 posts
    Member since:
    Jun 2008

    Posted 01 Aug 2008 Link to this post

    interesting
  11. Finn
    Finn avatar
    27 posts
    Member since:
    Jun 2008

    Posted 01 Aug 2008 Link to this post

    That's all fine George, but this is a forum for GridView for WinForms, not ASP.NET, as Martin pointed out.

    Finn

  12. Randw
    Randw avatar
    6 posts
    Member since:
    Jul 2007

    Posted 30 Mar 2009 Link to this post

    Hi,

    Q2 2008: I'm using the code to effectively load the filter expressions before I databind. That is, the filter is set in the UI.  However, the filter is not applied! It requires the user to change the filter somehow, then it is applied.  I'd try rebinding, but as I said, I'm setting the filter prior to binding.  How do I get the programmatically set filters to apply?

    Thanks,
    - Rand
  13. Randw
    Randw avatar
    6 posts
    Member since:
    Jul 2007

    Posted 30 Mar 2009 Link to this post

    Nevermind. Inexplicably, the filter settings are now applying. Guess I was holding my mouth the wrong way...
    - Rand
  14. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 31 Mar 2009 Link to this post

    Hi Randw,

    I am glad about that you have resolved your case in your own. Write me back if you have other questions. I will be glad if I can help you.

    All the best,
    Martin Vasilev
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  15. LT
    LT avatar
    9 posts
    Member since:
    Oct 2018

    Posted 21 Oct Link to this post

    Hi,

    Realize this thread was created a decade ago - but I'm unable to find much on the topic. Our users use the built in filtering feature with radGridView, but would like to be able to save their filter settings off and have it there ready to go on next program start up.

    The closest thing I can find is https://docs.telerik.com/devtools/winforms/controls/gridview/save-and-load-layout/save-and-load-layout. Is there some way I could adapt this to work with saving filters in XML for a WinForm app?

  16. Nadya
    Admin
    Nadya avatar
    109 posts

    Posted 23 Oct Link to this post

    Hello LT,

    The Save/Load functionality does save all properties that the end-user can change, including filter descriptors. I created a sample project demonstrating how to load and save a layout by changing some filter settings. Could you please refer to it and see how it works on your end?

    RadGridView serialization API provides a wide range of options that enable the programmer to customize the serialized content. Please refer to the following article for implementing custom serialization scenarios: https://docs.telerik.com/devtools/winforms/controls/gridview/save-and-load-layout/advanced

    I hope this helps. Should you have any other questions, I will be glad to help.

    Regards,
    Nadya
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  17. Gabriel
    Gabriel avatar
    2 posts
    Member since:
    Nov 2019

    Posted 08 Nov Link to this post

    Hi admins.

     

    You said a while back that you'd consider developping the save/load filter settings fonctions if people showed interest in it. I'M not sure if it has been done yet (can't seem to find anything regarding this in the doc), but otherwise, consider this a prove of interest!

     

    Best regards.

  18. Nadya
    Admin
    Nadya avatar
    109 posts

    Posted 08 Nov Link to this post

    Hello Gabriel,

    Thank you for writing.

    Save/Load layout functionality in RadGridView works for filtering settings as well. A test project is provided in my previous post. You can download it and see how it works for you. It could be greatly appreciated if you can provide more information about your scenario. Additional documentation on this topic is available here:

    https://docs.telerik.com/devtools/winforms/controls/gridview/save-and-load-layout/save-and-load-layout
    https://docs.telerik.com/devtools/winforms/controls/gridview/save-and-load-layout/advanced

    Do not hesitate to contact us if you are experiencing any difficulties.

    Regards,
    Nadya
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  19. Gabriel
    Gabriel avatar
    2 posts
    Member since:
    Nov 2019

    Posted 08 Nov in reply to Nadya Link to this post

    Hello Nadya.

     

    Ideally, what I would like to do is save and load filter settings as a DataBase object (a string, if possible), to be fetched and interpreted when my grid is populated.

  20. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3431 posts

    Posted 11 Nov Link to this post

    Hello, Gabriel, 

    The save/load layout functionality that RadGridView offers, stores the layout as an XML file and expects an XML for loading. However, you can store the XML to your database and extract the file whenever it is necessary. 

    I have found the following general programming threads which will give you useful information on this topic:
    https://stackoverflow.com/questions/4403523/is-it-bad-to-store-xml-in-a-database 
    https://www.codeproject.com/Questions/877425/how-to-insert-xml-data-in-sql-database-in-winform 

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

     

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top