Filter columns in DataGrid

1:26 PM

Recently i have encountered in some issue filtering columns in DataGrid. That can be achieved by following code :



The result of such code may look like following:



But there is some problem with this code :

  • When clicking on any column, we don't see any feedback it was clicked
  • No filter applied when clicked on column anyway
Actually the solution is very basic, although it need to be explained a little:
We defined CanUserSort on each DataGrid column. We defined CanUserSortColumns in whole DataGrid as well. But there we miss something small but important detail: Since we defined DataGridTemplate and we didn't define how we would like to sort, WPF doesn't know the way to sort for us our items.

In order to explain him, we should add property (SortMemberPath ="Property_name") in each DataGridTemplateColumn. So the following code will look similar to this:





As we can see we do get feedback when pressing on the specific columns and our items just sorted as we required !

P.S. Reason i have used images when introducing the code is the in the plain code part of the symbols was deleted by the blog engine.

You Might Also Like

0 comments.

Popular Posts

Total Pageviews