This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
The DataGridColumn.GroupRowHeaderTemplate is great. I'm wondering if it would be possible to have a GroupCellTemplate or something similar on the DataGridColumn. I'm wanting to have a different template for each column and have its content displayed underneath the column (in the cell). For example, I'd like to have totals or averages or both displayed for each column on the "GroupRowHeader" but I'd like the data to line up underneath the column. So one thought would be to have each column control its own cell for when the data is grouped. Then, just as the DataGridGroupingRow has a DataGridGroup and in turn a collection of children (items from ItemsSource collection within the particular group), I'd like to be able to access the collection of items to calculate a total, average, count or perform any other calculation and present the results in the cell. Please see the attached image. Let me know if you have any ideas. Thanks! |
|
|
Also, along with the previous request, I'd like to know how to best provide overall summary values (totals, averages, etc.). Do I need to calculate those things beforehand and modify the ItemsSource collection? I'd rather not modify the ItemsSource collection. I wonder if we could set a flag to state whether or not we want an overall summary row or not, then maybe the GroupCellTemplate from the previous post could be utilized for the overall summary cells (or provide another template for the overall summary).? I would think that these issues would be very common across your customer base. I know we run into these issues with almost all the grids we provide in our programs. Thanks for all you do! |
|
|
Hello Jared I really like the features you have mentioned here. These are certainly on our backlog, but I don't know when we'll begin implementing this. For the meantime, if you like, you could add this feature to the WPF Elements Think Tank: http://www.mindscapehq.com/thinktank/product/15. This can help increase its priority. For now you'll need to stick with using the GridRowHeaderTemplate. The template can display calculated values from multiple columns. You can have several text blocks beside each other, where each one can bind to the children of the group and use a converter to calculate average or min/max or sum or whatever you want for the group. The problem is, as you mentioned, these can't be ordered or lined up with their respective columns for now. Jason Fauchelle |
|
|
I've added these requests to the WPF Elements Think Tank as you suggested. I'm currently utilizing the GridRowHeaderTemplate. Currently, in order to get "overall" summary information would you suggest creating another column where every item has the same value and then grouping always by that column first? Or can you think of something better (without changing the underlying collection - ItemsSource)? Thanks! |
|
|
Hello Jared Thanks for adding those requests to the Think Tank. With your question here, I'm not entirely sure what you want to do. Could you please send a sample project or/and some screen shots to explain your data, the values you want to display and the way you want to group the data. Thanks. Jason Fauchelle |
|
|
Jason, If you look at the image attached (grid.png) with the first message in this thread, the grid is essentially grouped by the first two columns. The feature that I'm requesting is the ability to provide a DataTemplate tied to the column to layout the cell in the grouping row. If you look at the highlighted line in the image, I'd like to be able to calculate an average, total, or a count of the items within the group and provide the result(s) in the cell (underneath the column heading). I'm trying to get summary items for each column to line up underneath the column in the GroupRowHeader. Please see the attached images. It would be nice to be able to pass the items in the group once to calculate the summary items (total, average, etc.) rather than specifying a converter for each cell and passing the items once for each column. Ideally, we would pass the items once and return an object that we could bind against in the cell DataTemplate (DataGridColumn.GroupingCellTemplate). Hopefully, this helps to clarify the request. Please ask if you need further clarification. |
|
|
Hello Jared Thanks for this explanation, I understand what you want here. I'll experiment with achieving this effect and try get a sample to you tomorrow. Jason Fauchelle |
|
|
Hello Jared I have attached a sample that closely achieves what you want here. To run the sample, make sure to add a reference to your copy of the Mindscape.WpfElements.dll. When you run the sample, group the Name column to see the effect. This has been achieved using the existing GroupRowHeaderTemplate feature and so does not require a nightly build upgrade. To achieve this effect, the GroupRowHeaderTemplate contains an ItemControls. The items source uses a multi-value-converter that takes in the current group and the collection of columns from the data grid. The output of the converter is a collection of SummaryInfoColumn objects. These objects are simply tuples that contain a DataGridColumn and a SummaryInfo object. The SummaryInfo object contains all the calculated summary values such as the Name of the group, the start and end dates and the average sales value for the current group. All based on the images you sent. These values are calculated only once per group just as you wanted. This is done within the multi-value-converter, so each SummaryInfoColumn object produced by a single conversion will contain the same SummaryInfo instance. On the ItemsControl I mentioned, I created a custom template selector that selects a different template based on the name of the column of the SummaryInfoColumn. You could probably generalize this template selector implementation rather than having a property for each template. Each of the 3 templates contain 1 or more text blocks that bind to the appropriate properties of the SummaryInfo object for that group. The root of the templates is a border that binds the Width to the ActualWidth property of the column. This means each part of the template can line up with the appropriate column. This should give you a place to start with achieving the behavior you want. The idea of the GroupingCellTemplate is still on our mind, but we may not be able to add this in until the next version. Known issues with the sample I've sent you are: Reordering the columns does not update the order of the parts in the group template. The group template does not support scrolling if the columns exceed the available width of the DataGrid. Double clicking a column sizer does not consider the auto-width of the appropriate template (minor detail). Parts don't line up correctly when there are multiple grouping levels. Jason Fauchelle |
|
|
Jason, Thanks for your help and pointing me in the right direction. I've overcome a few of the issues you mentioned, but am still needing to tackle the scrolling issue. If you have any suggestions on this one, I'd appreciate hearing them. I used a converter to calculate the level embedded and how much left margin would be needed to line the parts up correctly within the column. Thanks for your help! This is a critical piece of our software (reporting summary items based on user's defined groupings - multiple levels). |
|
|
Hello Jared Here are the steps to add scrolling support to the group header template: 1) Create a new class that implements the IValueConverter interface. I called this GroupRowHeaderMarginConverter. In the Convert method, cast the value into a double, then return a new Thickness with a negative left margin like this:
2) In the resource dictionary containing all the header template code, add a new instance of this converter like this:
3) In the GroupRowHeaderTemplate there is an ItemsControl which uses a horizontal StackPanel in the ItemsPanel template to display the items. Set the Margin of this StackPanel to bind to the HorizontalOffset property of the data grid ScrollViewer, and use the margin converter like this:
4) Set ClipsToBounds=true on the ItemsControl within the GroupRowHeaderTemplate. Let me know if you have any questions about this. Jason Fauchelle |
|
|
Thank you Jason! That was perfect. I already had a converter in place to handle the correct indenting for multiple levels of grouping, but I was missing the binding to the HorizontalOffset property on the ScrollViewer. Thank you again for your help. You guys have been great! |
|