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
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.
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.
Just what I needed!
Finn
Why this:
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1) |
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.
Saving grid settings
http://www.telerik.com/help/aspnet-ajax/grdsavingsettingsonperuserbasis.html
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.
That's all fine George, but this is a forum for GridView for WinForms, not ASP.NET, as Martin pointed out.
Finn
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
- Rand
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.
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?
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
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.
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
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.
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