Hello there,
I am trying to pre-filter a grid the filter is working but the Filter pop-up does not reflect the active filters. This column is defined as:
<
telerik:RadGridView.Columns
><
BR
><
telerik:GridViewDataColumn
Header
=
"Status"
UniqueName
=
"Status"
DataMemberBinding="{Binding NeedsAttention,
Converter={StaticResource
myStateTextConverter}}"><
BR
><
telerik:GridViewDataColumn.CellTemplate
><
BR
><
DataTemplate
><
BR
><
Image
Source="{Binding NeedsAttention, Converter={StaticResource
myStateImageConverter}}"/><
BR
></
DataTemplate
><
BR
></
telerik:GridViewDataColumn.CellTemplate
><
BR
></
telerik:GridViewDataColumn
><
BR
>
myStateTextConverter returns "Attention Needed" if NeedsAttention property is true else returns "Completed". This is what is displayed in the Filter Popup. By virtue of the code below I am expecting the "Attention Needed" to be checked but it's not even though the filter is active and it is filtering out "Completed" records. What am I missing here?
Code in the Constructor
ColumnFilterDescriptor statusColumnFilter = new ColumnFilterDescriptor((IDataFieldDescriptor)this.radGridView.Columns["Status"]);
statusColumnFilter.FieldFilter.Filter1.Operator = FilterOperator.IsEqualTo;
statusColumnFilter.FieldFilter.Filter1.Value = "True";
this.radGridView.FilterDescriptors.Add(statusColumnFilter);
When I programmatically set the filter
?((Telerik.Windows.Controls.GridView.ColumnFilterDescriptor)(this.radGridView.FilterDescriptors[0]))
{( (Empty) AND (( (NeedsAttention IsEqualTo True ) )) )}
base {Telerik.Windows.Data.CompositeFilterDescriptor}: {( (Empty) AND (( (NeedsAttention IsEqualTo True ) )) )}
Column: {Telerik.Windows.Controls.GridViewDataColumn}
DistinctFilter: {Empty}
FieldFilter: {( (NeedsAttention IsEqualTo True ) )}
IsActive: true
When I set the filter using the Popup
?((Telerik.Windows.Controls.GridView.ColumnFilterDescriptor)(this.radGridView.FilterDescriptors[0]))
{( (( (NeedsAttention IsEqualTo True MC) )) AND (( (NeedsAttention IsEqualTo True ) )) )}
base {Telerik.Windows.Data.CompositeFilterDescriptor}: {( (( (NeedsAttention IsEqualTo True MC) )) AND (( (NeedsAttention IsEqualTo True ) )) )}
Column: {Telerik.Windows.Controls.GridViewDataColumn}
DistinctFilter: {( (NeedsAttention IsEqualTo True MC) )}
FieldFilter: {( (NeedsAttention IsEqualTo True ) )}
IsActive: true
9 Answers, 1 is accepted
I guess that you have forgotten to do something, but I am not sure what.
Please, take a look at my blog post. It provides a working example of pre-filtering RadGridView. The UI is correctly updated in the sample project on the blog.
You can use the sample project that is attached in the blog post to see what is the difference with your real project.
I hope this helps.
Ross
the Telerik team
I went through your sample but the sample does not have an example for boolean datatype column. In my application I changed the column binding to a string property (new wrapper property created based on the boolean I was binding to), applied the pre-filtering technique for strings from your blog and it works fine. It is NOT working with boolean type. My guess is that the telerik popup is getting confused when I am setting the Operator to IsEqualTo but in the popup for boolean there is no IsEqualTo. When I am trying the DistinctFilter.DistinctValues it is expecting a string type and giving me runtime error.
Thanks,
Manas
The boolean column is just like any other column. I am not sure why you think that the IsEqualTo is not applicable to boolean -- it is.
Since we can't see your code, we cannot really guess what you are doing.
Can you send us a small dummy sample project that demonstrates what exactly you are doing? Then tell us what are you trying to achieve. We will take a look at your project and try to modify so that it achieves your goal, if that is possible of course.
Thanks in advance.
Ross
the Telerik team
I changed your sample application and added a boolean bound column and added the pre-filter for the boolean column. The result is the data gets filtered but the filter popup is not in synch. I could not attach a zip file to the reply. Getting error "File is not of correct type. Try again. A file with the same name is already attached! Max total size exceeded 2MB: the max total size of all attached files Allowed extensions: .gif, .jpg, .jpeg, .png"
Following are the changes:
Player.cs:
public bool IsNumberAbove10
{
get { return (number > 10);}
}
Main.xaml.cs:
//var numberColumnFilter =
// new ColumnFilterDescriptor((IDataFieldDescriptor)this.playersGrid.Columns[1]);
//numberColumnFilter.FieldFilter.Filter1.Operator = FilterOperator.IsLessThan;
//numberColumnFilter.FieldFilter.Filter1.Value = 10;
//this.playersGrid.FilterDescriptors.Add(numberColumnFilter);
var numberColumnFilter =
new ColumnFilterDescriptor((IDataFieldDescriptor)this.playersGrid.Columns["IsNumberAbove10"]);
numberColumnFilter.FieldFilter.Filter1.Operator = FilterOperator.IsEqualTo;
numberColumnFilter.FieldFilter.Filter1.Value = "true";
this.playersGrid.FilterDescriptors.Add(numberColumnFilter);
Main.xaml:
<
telerik:GridViewDataColumn
Header
=
"Number Above 10?"
DataMemberBinding
=
"{Binding IsNumberAbove10}"
>
</
telerik:GridViewDataColumn
>
Thanks,
Manas
You have assigned the string "true" to the Value property. You have to assign the bool true. Booleans are different from strings. Remove the quotes around true and it will start working.
Anyway, setting Filter1.Value is not the best way since in the latter versions, the FilteringControl of boolean columns does not show the lower part (it is useless and redundant in the case of a boolean), my suggestion is to select the distinct value true. The FilteringControl of a boolean column shows only the upper part -- the two distinct values that a boolean has -- true and false. Here is how I have done it:
var numberColumnFilter =
new
ColumnFilterDescriptor((IDataFieldDescriptor)
this
.playersGrid.Columns[
"IsNumberAbove10"
]);
bool
selectedDistinctValue =
true
;
// This will programmatically check the true check-box as though the user has done it.
numberColumnFilter.DistinctFilter.DistinctValues.Add(selectedDistinctValue);
this
.playersGrid.FilterDescriptors.Add(numberColumnFilter);
I have created a sample project that does this. It uses the latest available binaries.
I hope this helps. Let me know if there are problems or if you want to achieve something different from my sample project.
Ross
the Telerik team
Thanks,
Manas
There is an event called DistinctValuesLoading which will be called each time the user opens the filtering pop-up. If you attach to it, you can manually set the distinct values that will be shown to the user by using the event arguments.
Since I am not sure where your data is coming from, the retrieval of absolutely all distinct values will be up to you. Have in mind that if the data is coming from a server and you want to get ALL distinct values, you will defeat the purpose of paging since you will go to the server and fetch everything.
So in a client-server scenario it might be a good idea to hide the distinct values list-box (the column has a property called ShowDistinctFilters) and let the user rely on the FieldFilter, i.e. the lower part where he has to manually type the search criteria.
I hope this helps.
Ross
the Telerik team
Great that helped.
Thank you very much for all your help,
Manas
I have a scenario is the following:
1. I am using "pop-up custom filter" with mvvm.
2. data for header filter was from server
3. I remember all selected filter values then save to database
4. when user selects any this stored filter, its values will be parsed and connect to db to fetch data for grid.
5. at this time, i need to set the corressponding filter header to IsActive = true while header filter has not yet created.
I have taken a look at on this thread for "Pre-filter". But it seems must make dirty on column with filter value.
Is there the way to set IsActive to true without perform any filtering on column?
Thanks
don