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

DataFormatString in Group By Expression

5 Answers 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Levi
Top achievements
Rank 1
Levi asked on 19 Oct 2008, 09:09 PM
Is there a way to include the DataFormatString inside a group by expression? 

GroupByExpression

 

="StartTimeGB Arrived Group By StartTimeGB"

 

There are examples of how to declare one using markup, but all of them cause the grid to come up grouped by default, which I don't want. How can I do this without the default grouping?

Thanks,
Levi

5 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 21 Oct 2008, 02:48 PM
Hello Levi,

Can you elaborate more on your scenario? Do you mean that you need to modify the GroupHeader text? If yes. please review this help topic.

In addition you can have a look at the following links for further information on RadGrid group-by expressions:
http://www.telerik.com/help/aspnet-ajax/grdgroupbydeclarativedefinition.html
http://www.telerik.com/help/aspnet-ajax/grdgroupbyprogrammaticdefinition.html

Let me know if I can help you further.

Kind regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Levi
Top achievements
Rank 1
answered on 21 Oct 2008, 03:43 PM

Both those examples cause the grid to come up grouped by default, which I don't want. I want the user to initiate the grouping by dragging and dropping the column... and then the string is properly formatted. I did find a temporary solution however, although it is kind of whacky. I have to remove the field and then re-add it so I can apply the dataformatstring. Is there a better way? I don't see why you can't define a group by field without it coming up grouped by default when the grid loads...

protected void RadGridSummary_GroupsChanging(object source, Telerik.Web.UI.GridGroupsChangingEventArgs e)
        {           

            if (e.Action == GridGroupsChangingAction.Group)
            {
                if (e.Expression.GroupByFields[0].FieldName == "StartTimeGB")
                {
                    GridGroupByField gbfNew = new GridGroupByField();
                    gbfNew.FieldName = "StartTimeGB";
                    gbfNew.FieldAlias = "Arrived";
                    gbfNew.FormatString = "{0:D}";                   

                    e.Expression.SelectFields.Clear();
                    e.Expression.SelectFields.Add(gbfNew);                   

                    e.Expression.GroupByFields.Clear();
                    e.Expression.GroupByFields.Add(gbfNew);                   
                }

            }
        }

0
Iana Tsolova
Telerik team
answered on 22 Oct 2008, 08:53 AM
Hello Levi,

Indeed if you set your group-by expression on Page_Load or declaratively, it is expected that the grid will be initially grouped. This is because the purpose of setting group-by expression to RadGrid is to group it.

However if you would like to change the formatting of the group header, you can do using you implementation or customize the GridGroupHeaderItem as shown in the following topic:

http://www.telerik.com/help/aspnet-ajax/grdcustomizegridgroupheaderitem.html

I hope this helps.

Best wishes,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Basel Nimer
Top achievements
Rank 2
answered on 03 May 2010, 12:41 PM
am getting this error
"Value of type 'Telerik.Web.UI.GridItem' cannot be converted to 'Telerik.WebControls.GridGroupHeaderItem"


at compilation time when trying to

Dim item As Telerik.WebControls.GridGroupHeaderItem = CType(e.Item, Telerik.WebControls.GridGroupHeaderItem)



0
Iana Tsolova
Telerik team
answered on 03 May 2010, 03:35 PM
Hello Basel,

Try modifying your code as below and let me know if it makes any difference:

Dim item As Telerik.Web.UI.GridGroupHeaderItem = CType(e.Item, Telerik.Web.UI.GridGroupHeaderItem)


All the best,
Iana
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.
Tags
Grid
Asked by
Levi
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Levi
Top achievements
Rank 1
Basel Nimer
Top achievements
Rank 2
Share this question
or