I would like to handle sorting in a custom way. I know I can use Sorting event for this and set e.Cancel = true. This way I can stop grid from performing sorting on its own.
The problem is that I would still like to have a sorting indicator in the header (near label). I can accomplish that by adding following line to the Sorting event handler:
e.FieldLayout.SortedFields.Add(e.SortDescription);
but after that the default sorting mechanism executes despite setting e.Cancel = true. What's your ideas on that?
Thanks for the response.
Your solution solves the issue, but seems to be complicated for this particular task (as far as filtering is concerned). I guess there is simply no easy answer for this.
Currently I simply do sorting/filtering work twice: once by myself and second time - let the grid do it. Since my sorting and filtering uses the same principles for comparison, but does it on the SQL level, XamDataGrid default behavior does not break sort order or change filtered rows. This means user should not see the difference.
That's why for now I will stay with the current approach, but your response Stefan for sure is an answer for this issue and thanks for that.
Hello,
I have modified the sample I sent you before, so now it has the functionality you want. When you use the UI of the XamDataGrid, the built-in filtering doesn’t filter the XDG. I made the clear buttons to be visible, when a value is entered in the some of the Textboxes. All you need to do is write your custom filtering for the data source. In the sample there is example with the equals filter operator. Here you can see how to filter your CollectionView:
http://msdn.microsoft.com/en-us/library/ms752348.aspx
Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Hi Stefan,
thanks for your reply.
In my scenario I want to use XamDataGrid UI to perform sorting and filtering (i.e. clicking label for sorting and using filter record for filtering) and I want the UI to behave exactly the same as usual. The only difference is that I don't want XamDataGrid to perform sorting and filtering on its own, I want to do it by myself directly on the collection bound to the DataSource property.
In the project you sent me you showed how to perform custom sorting and filtering and how to control sort indicator programatically, which solves my sorting issue. However when peforming custom filtering you don't show any filtering UI (like filter record), which I would like to use and see in this case. How to accomplish that?
I have been looking into the project I sent you before and I modified, so now the Sorting and Filtering is made directly to the DataSource and a sort indicator is shown if there is sorting. Also I can say that the Sorting and Filtering events of the XamDataGrid are fired if you sort or filter using the UI of the control, if do this by code, no matter if you modify the RecordFilters or SortedFields collection the events are not fired. In my sample I handled both events and canceled them, but it is not necessarily if you don’t use the UI for sorting and filtering. Please let me know if this helps you or you need further assistance on this matter.
Thanks for the reply.
The sample project you created shows exactly the issue I'm having.
Even though you set e.Cancel = true for the Sorting event, after adding SortDescription you can see that grid gets sorted the first time you click any label. This means that adding SortDescription triggers sorting somehow and setting e.Cancel = true does not help here.
For filtering I'm using RecordFilterChanging event in analogic way as for sorting and I'm observing the same behavior: modifying RecordFilters collection on FieldLayout also triggers default filtering even though I set e.Cancel = true.