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

Pre-filter GridView

9 Answers 115 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Manas
Top achievements
Rank 1
Manas asked on 06 May 2011, 07:06 PM

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

Sort by
0
Rossen Hristov
Telerik team
answered on 09 May 2011, 08:45 AM
Hi Manas,

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.

Kind regards,
Ross
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Manas
Top achievements
Rank 1
answered on 11 May 2011, 05:40 PM
Hello Ross,
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
0
Rossen Hristov
Telerik team
answered on 11 May 2011, 05:45 PM
Hello 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.

All the best,
Ross
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Manas
Top achievements
Rank 1
answered on 11 May 2011, 07:08 PM
Hello Ross,
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. 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
0
Accepted
Rossen Hristov
Telerik team
answered on 12 May 2011, 08:36 AM
Hello 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.


Greetings,
Ross
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Manas
Top achievements
Rank 1
answered on 12 May 2011, 04:22 PM
Thanks Ross, this is working for boolean but there seems to be a bigger problem: The filter popup is showing options that are true for the current page only, values on other pages are not displayed in the Popup as filtering options. For example if I am displaying New Orders and Completed Orders in the grid and on the first page I have only New Orders (when there is no filter) then when I click on filter icon it only shows the "New" option only. Please note completed Orders are there on 3rd or 4th page and when I click on filter icon while I am on the 3rd or 4th page with Completed Orders as welll I see both "New" and "Completed" options in the filter popup. Do you have a solution for this?

Thanks,
Manas
0
Accepted
Rossen Hristov
Telerik team
answered on 12 May 2011, 04:39 PM
Hi 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.

Regards,
Ross
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Manas
Top achievements
Rank 1
answered on 12 May 2011, 07:04 PM
Hello Ross,
Great that helped.

Thank you very much for all your help,
Manas
0
donvn
Top achievements
Rank 1
answered on 23 Nov 2011, 12:28 PM
hi Ross,

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

Tags
GridView
Asked by
Manas
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Manas
Top achievements
Rank 1
donvn
Top achievements
Rank 1
Share this question
or