In the WPF XamGrid is there a way to get a the sort indicator in the header to also show the sorting priority?
In other words, if I'm sorting ascending on two columns, can I get the XamGrid column to show me which is sorted first and which is second? I understand this type of feature is available in some IG datagrids, but maybe not this one.
I'd rather not re-invent the wheel if I'm overlooking something that already exists. Even a tooltip would probably be sufficient (eg. hovering over the sort indicator would show the sorting priority of the grid).
If I have to do this manually I'm thinking I'd create a new template for the column header, and try a tooltip approach. Please let me know if there are any suggestions along this line. Ideally I'd be looking for an approach that's not too elaborate since this confusion over sorting behavior doesn't come up all that frequently.
Hello dbeavon,
Thank you for your post.
I have been investigating into this issue, and I would recommend that you begin by including the default style for HeaderCellControl. This element is what makes up the headers in the XamGrid, and its default style can be found in the generic.shared.xaml file commonly found at the following directory: C:\Program Files (x86)\Infragistics\<your version here>\WPF\DefaultStyles\XamGrid.
The template of the HeaderCellControl contains a Grid element named "SortAndPinIndicators." This is where I would recommend placing your tooltip, or other customization to the grid. The sort priority of the XamGrid columns will correspond directly to the index of that column in the XamGrid.SortingSettings.SortedColumns collection. Knowing this, I would recommend a MultiBinding for the Tooltip property of that "SortAndPinIndicators" grid, along with an IMultiValueConverter. These bindings can be to the HeaderCellControl (template parent), and the HeaderCellControl's Column.IsSorted property. The second bit is to ensure that the converter's Convert method will fire when the IsSorted property of a specific column changes.
Using the HeaderCellControl in the converter, you can obtain the XamGrid from that HeaderCellControl, and then use the XamGrid.SortingSettings.SortedColumns.IndexOf(HeaderCellControl.Column) method to find the index that the column exists in for the sorted columns collection of the XamGrid. Then, you can return a tooltip string based on that index.
I have attached a sample project to demonstrate the above. I hope this helps you.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Andrew,
Thank you very much for your effort on this. I will definitely use it. I may try to programmatically dig down to the SortAndPinIndicators in order to attach a tooltip as you did, maybe as a part of the loaded event. (Overriding the entire control template of the HeaderCellControl seems a bit heavy-handed, albeit perhaps the right XAML-oriented approach.)
Whenever I run into some missing feature in the old "XamGrid", I always review the *XamDataGrid* to see if anything would have been different, had I used that instead. Am I right to assume that I would also have to implement this feature on my own with that control too? I checked out the examples (eg "IGDataGrid.Samples.Organization.FieldSorting") and they don't provide any indicators for sort order/priority either.
Thanks again,
David
You could possibly try to dig down to the SortAndPinIndicators programmatically in order to attach a tooltip, but I think I would still highly recommend the overridden HeaderCellControl template for this, as it may be rather tedious to dig down to the SortAndPinIndictors for each column if you have many columns in your XamGrid.
Regarding the XamDataGrid, you are correct to assume that this feature is not currently built into that control either. Like the solution I had proposed for the XamGrid, I would recommend modifying the template of the element that makes up the headers of the XamDataGrid as well. This control is called the LabelPresenter. There are a couple of differences with the XamDataGrid though, in that the XamDataGrid does not have a directly accessible SortedFields collection on it. This collection exists on the FieldLayout, but you can get that from the Field's Owner property by using a very similar method to the one I had recommended above.
In the case that you would still like to go this route, I have attached a sample project demonstrating sort priority in the XamDataGrid as well. I hope this helps you.
Thanks a lot. I think I'm all set.
I had told myself to start using the XamDataGrid as my "goto" grid a long time ago. But I don't listen well and whenever I'm in a hurry I end up copying from something I'd built previously with the XamGrid.
As a side, I'm looking forward to seeing your UWP datagrid some day too. If you guys ever have a preview ready I'd be glad to start trying it.
Thank you for your interest in a UWP data grid. While I currently have nothing to report regarding a preview of a UWP data grid, I would recommend that you keep an eye on our blogs (http://ko.infragistics.com/community/blogs/). When we have something to share regarding UWP, it will be posted there for all to see.