Rob Ainscough
Top achievements
Rank 1
Rob Ainscough
asked on 20 Dec 2012, 12:33 AM
I'm trying to setup a pre-defined filter on a column in my XAML. I can't see to find how to do that?
For example I have a NON-VISIBLE column called "Remove" and the data bound to the grid will have a True/False value in this column. I want to have a Filter "pre-defined" that will filter when the value in the Remove column/field = True.
I saw the sample on how to setup a Filter in CodeBehind, but I'm MVVM and don't want to do that.
Can someone show me a code sample on how to setup a Filter in XAML? If not, how to get a filter defined using MVVM approach?
Thanks, Rob
For example I have a NON-VISIBLE column called "Remove" and the data bound to the grid will have a True/False value in this column. I want to have a Filter "pre-defined" that will filter when the value in the Remove column/field = True.
I saw the sample on how to setup a Filter in CodeBehind, but I'm MVVM and don't want to do that.
Can someone show me a code sample on how to setup a Filter in XAML? If not, how to get a filter defined using MVVM approach?
Thanks, Rob
5 Answers, 1 is accepted
0
Hello,
The only way to set a column filter would be as described in this article.
You can put all this code-behind logic in an attached behavior to achieve MVVM-friendly architecture. The simply turn on the attached behavior on the grid and the logic will kick-in.
Greetings,
Rossen Hristov
the Telerik team
The only way to set a column filter would be as described in this article.
You can put all this code-behind logic in an attached behavior to achieve MVVM-friendly architecture. The simply turn on the attached behavior on the grid and the logic will kick-in.
Greetings,
Rossen Hristov
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
0
Rob Ainscough
Top achievements
Rank 1
answered on 20 Dec 2012, 05:19 PM
Hi Rossen,
I actually found what I needed to add to my XAML ... the article you pointed me to seems like a lot more work than is needed. I was able to use telerik:RadGridView.FilterDescriptors in my XAML. This works, but the problem I've run into now is that my delete button in the grid will actually remove the item from my bound ObservableCollection ... so I thought I could simply cancel (e.Cancal = True) in the Deleting event and set the Remove item = True. However, when I do this, the GridView isn't being refreshed. Is there any way to force a GridView refresh?
I actually found what I needed to add to my XAML ... the article you pointed me to seems like a lot more work than is needed. I was able to use telerik:RadGridView.FilterDescriptors in my XAML. This works, but the problem I've run into now is that my delete button in the grid will actually remove the item from my bound ObservableCollection ... so I thought I could simply cancel (e.Cancal = True) in the Deleting event and set the Remove item = True. However, when I do this, the GridView isn't being refreshed. Is there any way to force a GridView refresh?
<
telerik:RadGridView
x:Name
=
"CustomerNotesGridView"
AreRowDetailsFrozen
=
"True"
AutoGenerateColumns
=
"False"
CanUserFreezeColumns
=
"False"
CanUserReorderColumns
=
"False"
CanUserResizeColumns
=
"False"
CanUserSortColumns
=
"False"
RowIndicatorVisibility
=
"Collapsed"
ShowGroupPanel
=
"False"
IsReadOnly
=
"False"
ItemsSource
=
"{Binding Path=Customer.CustomerNotes, Mode=TwoWay}"
>
<
i:Interaction.Triggers
>
<
i:EventTrigger
EventName
=
"Deleting"
>
<
ei:CallMethodAction
TargetObject
=
"{Binding}"
MethodName
=
"DeletingNote"
/>
</
i:EventTrigger
>
<
i:EventTrigger
EventName
=
"Deleted"
>
<
ei:CallMethodAction
TargetObject
=
"{Binding}"
MethodName
=
"DeletedNote"
/>
</
i:EventTrigger
>
<
i:EventTrigger
EventName
=
"RowActivated"
>
<
ei:CallMethodAction
TargetObject
=
"{Binding}"
MethodName
=
"SelectedNote"
/>
</
i:EventTrigger
>
</
i:Interaction.Triggers
>
<
telerik:RadGridView.FilterDescriptors
>
<
telerik:FilterDescriptor
x:Name
=
"CustomerNoteFilterRemovals"
Member
=
"Remove"
Operator
=
"IsEqualTo"
Value
=
"False"
IsCaseSensitive
=
"False"
/>
</
telerik:RadGridView.FilterDescriptors
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"CustomerNotesMAPID"
IsVisible
=
"False"
DataMemberBinding
=
"{Binding CustomerNotesMAPID}"
/>
<
telerik:GridViewDataColumn
Header
=
"SiteID"
IsVisible
=
"False"
DataMemberBinding
=
"{Binding SiteID}"
/>
<
telerik:GridViewDataColumn
Header
=
"CustomerAccount"
IsVisible
=
"False"
DataMemberBinding
=
"{Binding CustomerAccount}"
/>
<
telerik:GridViewDataColumn
Header
=
"CustomerNotesID"
IsVisible
=
"False"
DataMemberBinding
=
"{Binding CustomerNotesID}"
/>
<
telerik:GridViewDataColumn
Header
=
"Remove"
IsVisible
=
"False"
DataMemberBinding
=
"{Binding Remove}"
IsFilterable
=
"True"
/>
<
telerik:GridViewDataColumn
x:Name
=
"CustomerNoteSelectedColumn"
Header
=
""
Width
=
"25"
DataMemberBinding
=
"{Binding CustomerNotesCritical}"
IsReadOnly
=
"True"
IsFilterable
=
"False"
>
<
telerik:GridViewDataColumn.CellTemplate
>
<
DataTemplate
>
<
RadioButton
x:Name
=
"NoteSelectedRadioButton"
GroupName
=
"NotesGroup"
IsChecked
=
"{Binding CustomerNotesCritical, Mode=TwoWay}"
Tag
=
"{Binding}"
>
<
i:Interaction.Triggers
>
<
i:EventTrigger
EventName
=
"Click"
>
<
ei:CallMethodAction
TargetObject
=
"{Binding Path=DataContext, RelativeSource={RelativeSource AncestorType=UserControl}}"
MethodName
=
"NotesRadioButtonSelected"
/>
</
i:EventTrigger
>
</
i:Interaction.Triggers
>
</
RadioButton
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellTemplate
>
</
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
Header
=
"Date"
Width
=
"72"
DataMemberBinding
=
"{Binding CustomerNoteDateTime}"
IsReadOnly
=
"True"
IsSortable
=
"True"
/>
<
telerik:GridViewDataColumn
Header
=
"Note"
Width
=
"195"
DataMemberBinding
=
"{Binding CustomerNotesMember}"
IsReadOnly
=
"True"
/>
<
telerik:GridViewDataColumn
Header
=
"User"
Width
=
"84"
DataMemberBinding
=
"{Binding UserID}"
IsReadOnly
=
"True"
IsSortable
=
"True"
/>
<
telerik:GridViewColumn
CellTemplate
=
"{StaticResource DCRadDeleteMiniButton}"
FooterTextAlignment
=
"Center"
IsResizable
=
"False"
IsGroupable
=
"False"
IsFilterable
=
"False"
TextAlignment
=
"Center"
Width
=
"30"
Background
=
"Transparent"
HeaderTextAlignment
=
"Center"
IsSortable
=
"False"
IsReorderable
=
"False"
ShowDistinctFilters
=
"False"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
0
Rob Ainscough
Top achievements
Rank 1
answered on 20 Dec 2012, 10:55 PM
I also tried Attached Behavior route, but that produces the same results at just adding FilterDescriptors to my XAML.
I made the "Remove" column visible to see if my values were getting updated, they are ... however the filter does NOT seem to get triggered after the values are update? The filter works fine on the initial binding of data (my ObservableCollection).
I can manually (user interaction) select the filter from the "Remove" column and it will filter out as expected. It's as if the filter is not being triggered whenever any changes are made in my ObservableCollection (either Adding or editing and no Filter is triggered). So I added code-behind for the Filtering event and noticed that it never gets triggered programmatically but does get triggered with user interaction.
Is this a bug? If not, how do I force a GridView to re-evaluate the data with filters?
Thanks, Rob.
I made the "Remove" column visible to see if my values were getting updated, they are ... however the filter does NOT seem to get triggered after the values are update? The filter works fine on the initial binding of data (my ObservableCollection).
I can manually (user interaction) select the filter from the "Remove" column and it will filter out as expected. It's as if the filter is not being triggered whenever any changes are made in my ObservableCollection (either Adding or editing and no Filter is triggered). So I added code-behind for the Filtering event and noticed that it never gets triggered programmatically but does get triggered with user interaction.
Is this a bug? If not, how do I force a GridView to re-evaluate the data with filters?
Thanks, Rob.
0
Accepted
Hello,
Filtering is not automatically re-applied when the underlying data changes and this is by design due to performance considerations.
If you want to update the view, you have to "tell" the grid that data has changed as described in this article.
Alternatively, you can call the Rebind method in order to refresh the current view.
All the best,
Rossen Hristov
the Telerik team
Filtering is not automatically re-applied when the underlying data changes and this is by design due to performance considerations.
If you want to update the view, you have to "tell" the grid that data has changed as described in this article.
Alternatively, you can call the Rebind method in order to refresh the current view.
All the best,
Rossen Hristov
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
0
Rob Ainscough
Top achievements
Rank 1
answered on 26 Dec 2012, 04:41 PM
Rossen,
That worked, the EditItem and CommitItem (in a Deleting event always setting e.Cancel = True so it's not actually removed from the collection) seemed to force the filter to apply to the Collection. So my "deleted" (aka Removed) items are still part of the collection but no longing showing in my GridView (per filter) -- which is exactly what I want.
Thank you.
Rob
That worked, the EditItem and CommitItem (in a Deleting event always setting e.Cancel = True so it's not actually removed from the collection) seemed to force the filter to apply to the Collection. So my "deleted" (aka Removed) items are still part of the collection but no longing showing in my GridView (per filter) -- which is exactly what I want.
Thank you.
Rob