This is a migrated thread and some comments may be shown as answers.

Saving/loading filter settings

19 Answers 634 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Finn
Top achievements
Rank 1
Finn asked on 21 Jul 2008, 08:49 PM

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)

 

 

19 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 24 Jul 2008, 08:37 AM
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.
0
Finn
Top achievements
Rank 1
answered on 25 Jul 2008, 10:09 PM
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?
0
Accepted
Martin Vasilev
Telerik team
answered on 28 Jul 2008, 12:25 PM
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.
0
Finn
Top achievements
Rank 1
answered on 29 Jul 2008, 12:46 AM
Thank you Martin.

Just what I needed!

Finn
0
Finn
Top achievements
Rank 1
answered on 29 Jul 2008, 12:56 AM
Oh, one question:
Why this:
       System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1) 
 
and not just i = i + 1?

Finn
0
Accepted
Martin Vasilev
Telerik team
answered on 29 Jul 2008, 01:34 PM
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.
0
Mike
Top achievements
Rank 1
answered on 31 Jul 2008, 04:07 PM
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

0
Martin Vasilev
Telerik team
answered on 01 Aug 2008, 12:34 PM
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.
0
Mike
Top achievements
Rank 1
answered on 01 Aug 2008, 01:15 PM
interesting
0
Finn
Top achievements
Rank 1
answered on 02 Aug 2008, 02:38 AM

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

Finn

0
Randw
Top achievements
Rank 1
answered on 30 Mar 2009, 06:29 PM
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
0
Randw
Top achievements
Rank 1
answered on 30 Mar 2009, 07:02 PM
Nevermind. Inexplicably, the filter settings are now applying. Guess I was holding my mouth the wrong way...
- Rand
0
Martin Vasilev
Telerik team
answered on 31 Mar 2009, 01:10 PM
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.
0
LT
Top achievements
Rank 1
answered on 21 Oct 2019, 06:35 PM

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?

0
Nadya | Tech Support Engineer
Telerik team
answered on 23 Oct 2019, 01:12 PM

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.
0
Gabriel
Top achievements
Rank 1
answered on 08 Nov 2019, 01:29 PM

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.

0
Nadya | Tech Support Engineer
Telerik team
answered on 08 Nov 2019, 02:41 PM

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.
0
Gabriel
Top achievements
Rank 1
answered on 08 Nov 2019, 02:51 PM

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.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 11 Nov 2019, 01:53 PM
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.
Tags
GridView
Asked by
Finn
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Finn
Top achievements
Rank 1
Mike
Top achievements
Rank 1
Randw
Top achievements
Rank 1
LT
Top achievements
Rank 1
Nadya | Tech Support Engineer
Telerik team
Gabriel
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or