This is a migrated thread and some comments may be shown as answers.

Grouping and data formatting

11 Answers 408 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kakone
Top achievements
Rank 1
Kakone asked on 22 Oct 2010, 09:51 AM
Hello,

When the user drags a column with a data format to the group header, he can't see any value into the group rows (screenshot in attachment).

As there is no DataFormatString property on the GroupDescriptor class, how the group columns can be formatted ?

Cordially,
Kakone.

11 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 22 Oct 2010, 11:31 AM
Hi Stephane,

Did you define a GroupHeaderTemplate for the RadGridView?
If you do so I would suggest you to follow this markup:

<telerik:RadGridView.GroupHeaderTemplate>
    <DataTemplate>
        <TextBlock Text="{Binding Group.Key}"/>
    </DataTemplate>
    </telerik:RadGridView.GroupHeaderTemplate>
    <telerik:RadGridView.GroupDescriptors>
    <telerik:GroupDescriptor Member="Property3"/>
</telerik:RadGridView.GroupDescriptors>
<telerik:RadGridView.Columns>
              <telerik:GridViewDataColumn Header="Property3" DataMemberBinding="{Binding Property3}"   DataFormatString="{}{0:M/dd/yyyy}"/>
</telerik:RadGridView.Columns>

I suppose that you have supplied a DataFormatString property in your GridViewDataColumn that is used to display the date? 

If the suggestions above are not helpful please send us an example that illustrates this issue. 

Kind regards,
Vanya Pavlova
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Kakone
Top achievements
Rank 1
answered on 22 Oct 2010, 02:03 PM
I found why I couldn't see any value into the group rows.
I wrote this :
DataFormatString="M/dd/yyyy"
instead of
DataFormatString="{}{0:M/dd/yyyy}"

The data format string "M/dd/yyyy" works into the rows but not into the group rows.

But, I still have some problems.
First case : two columns with different DataFormatString are bound to the same property. I can't group by the second column. It's always the formatting of the first column that appears into the group rows.
Another case : I want to group my gridview by a member (with data format) but there is no column bound to the same member in my gridview (I you group by a member, to have the same column in the grid is unnecessary because you have the value in the group row). So, I can't define any formatting in the group.

Cordially,
Kakone.
0
Accepted
Yavor Georgiev
Telerik team
answered on 22 Oct 2010, 02:08 PM
Hi Kakone,

 You can try our Q3 Beta release - grouping in RadGridView is tweaked and you should have no problems when grouping by either column. It will get the correct DataFormatString.

Kind regards,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Kakone
Top achievements
Rank 1
answered on 22 Oct 2010, 03:04 PM
Thanks for the answer, it works very well in the Q3 Beta Release.
It's perfect for me.
0
Guru
Top achievements
Rank 2
answered on 14 Feb 2013, 09:00 PM
We are using 2012 Q3 and have the issue of group header template not displaying as the format of the values in the grid.

We generate columns all in code behind and have header template in the grid xaml.

Are we doing something wrong?

  • Column DataFormatString = "{0:MM/dd ddd}"
  • Group style is Flat

Here is our data template:
                                        <telerik:RadGridView.GroupHeaderTemplate>
                                            <DataTemplate>
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBlock Foreground="Red" Text="{Binding Column.Tag}"/>
                                                    <TextBlock Text="  " />
                                                    <TextBlock Text="{Binding Group.Key}" />
                                                </StackPanel>
                                            </DataTemplate>
                                        </telerik:RadGridView.GroupHeaderTemplate>

Should we use something other than Group.Key?

Shows as "01/01 Mon" in grid, but "01/01/2013 12:00:00" in group header.
0
Maya
Telerik team
answered on 15 Feb 2013, 08:52 AM
Hello Zack,

It is expected that if you predefine the group header template, not to have the format string applied in the group row. What you can try is to define StringFormat property of the binding. If you want it to be only for a certain column, you can create the GroupHeaderTemplate only for it:

<telerik:GridViewDataColumn DataMemberBinding="{Binding StadiumCapacity}"
                                          Header="Stadium"
                                          DataFormatString="{}{0:C}">
                  <telerik:GridViewDataColumn.GroupHeaderTemplate>
                      <DataTemplate>
                          <StackPanel Orientation="Horizontal">                            
                              <TextBlock Text="{Binding Group.Key, StringFormat=\{0:C\}}" />
                          </StackPanel>
                      </DataTemplate>
                  </telerik:GridViewDataColumn.GroupHeaderTemplate>
              </telerik:GridViewDataColumn>
 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Guru
Top achievements
Rank 2
answered on 15 Feb 2013, 04:04 PM
Our grid is based on a datatable that is defined by the user at runtime and bound to the grid at runtime.
It has 150+ possible columns the user choose to have in the grid and the column ResultFormatString is generated depending on the datatable column datatype (varchar/datetime/int/etc) also at runtime...

I would really like to define programatically when the columns are generated for the grid at runtime what group header template format should be since they can group by any column it would be very hard to predefine every situation.
Is there a straight forward way to define per column the format.

All we want to achieve is when they group, instead of just showing the value of the Group.Key but to show the column name also in the group header next to the Group.Key... maybe a template selector to send the group header a string to display? Do you have a sample project or anything that would show the best way to achieve this in WPF .NET 4 2012 Q3?
0
Maya
Telerik team
answered on 18 Feb 2013, 08:05 AM
Hi Zack,

You can take a look at this demo for a reference on how to create group header template selectors. Will that approach suit your needs ?   

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Guru
Top achievements
Rank 2
answered on 25 Feb 2013, 06:49 PM
I am having a hard time trying to figure out how to apply this to our situation... we give the user an editor that allows them to select the columns and specifiy things like the ResultFormatString. I can't predefine templates for every scenario. For example if a DateTime column is chosen they can specify any combination of mm dd yy hh mm ss etc...). With standard grouping this format is retained just fine, I just can't figure out yet a way to add the column name beside the Group.Key value without losing the formatting... Maybe I could build the datatemplate all together in a selector? It would be real nice if I could simply change the template but retain formatting for the value of Group.Key.
0
Maya
Telerik team
answered on 27 Feb 2013, 02:30 PM
Hello Zack,

My suggestion above - working with TemplateSelector - is probably not applicable when you need to change the format explicitly. What you can try is to assign the template during Grouping event for example:

private void clubsGrid_Grouping(object sender, GridViewGroupingEventArgs e)
        {
            (e.GroupDescriptor as ColumnGroupDescriptor).Column.GroupHeaderTemplate = this.Resources["template"] as DataTemplate;
        }

In this case 'template" DataTemplate is predefined in xaml, but you can try creating it in code-behind depending on the column and the string format that you want to apply. 

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Guru
Top achievements
Rank 2
answered on 13 May 2013, 09:24 PM
Ok, finally got back to this and was able to create the datatemplate in code on grid grouping and that works.

Problem then was that we save the grid (grouping, sorting, column order) with persistence framework and reload its settings when the user loads the grid on-demand, but when it is reloaded the group header templates do not get generated, only when the user is physically grouping the grid within the user interface does it get the datatemplate based group header.

First we attempted to listen for the grid Loaded event and iterate group descriptors to fix this but they are not loaded yet at that time so it was no luck.

Next we tried to listen for when the grid settings were loaded and then iterate group descriptors and set the templates. This finally worked for us.

Thanks for the assistance.
Tags
GridView
Asked by
Kakone
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Kakone
Top achievements
Rank 1
Yavor Georgiev
Telerik team
Guru
Top achievements
Rank 2
Maya
Telerik team
Share this question
or