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

Group by a substring of column

4 Answers 142 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Renu
Top achievements
Rank 1
Renu asked on 03 Feb 2009, 05:05 AM
Hi,
I have a column in grid view which contain Date Time. Requirement is to add group by expressions for date part of column.
We do not want to make Time string to be a part in grouping.

4 Answers, 1 is accepted

Sort by
0
Prad
Top achievements
Rank 2
answered on 03 Feb 2009, 06:13 PM

You can do this by setting column FormatString = "{0:MM/dd/yyyy}"

Regards
Prad
0
Renu
Top achievements
Rank 1
answered on 04 Feb 2009, 08:40 AM
Hi Pradeep,

I tried it in this way 

radGridView1.MasterGridViewTemplate.GroupByExpressions.Add("none([column3]) as Date format {0:MM/dd/yyyy} group by column3");



But things did not work out. Please let me know if i am making some mistake in it.


Thanks and regards,
Renu
0
Fabien
Top achievements
Rank 2
answered on 04 Feb 2009, 09:14 AM
Infact,

Pradeep proposed you to set parameter of formatString in the Column definition, not in the GroupBy expression ;)

ok, You cannot set a GroupBy with a substring in a column.

Here is a sample of. (You should read documentation about aggregate key words)
....GroupByExpressions.Add("Col1 as Brand format \"{1} - \", sum(ColWithDecimal) as Total format \"{0}: {1} Units | \" Group By Col1"); 

So for me to do this there is two ways.
If the format string in the date column is not the same as you need for your group by expression, you need an other column, with a different formatstring.

If it's the same format, keep it and group by expression should be
....GroupByExpressions.Add("column3 as Date format \"{1}\" Group By column3"); 

 As you can read on it, {0} is the "as" name : here the 'Date' word. And {1} is the value in the column.

This is correct  expression
"column3 as Date format \"{0} is {1}\" Group By column3" 

This is incorrect expression
"column3 as Date To use format \"{0} is {1}\" Group By column3" 
No space in the name ^^

If you need a specific presentation, you shall do this:
"column3 as Date format \"My Specific presentation: {1}\" Group By column3" 


Please, read documentation next time :)

Some questions? Don't hesitate.

Best regards,

Fabien


EDIT:
I forgot to give you an example of formatStirng in the column (I don't use IDE to create it but this is the same thing)
                GridViewDecimalColumn Country_Column = new GridViewDecimalColumn("FR", country.Code); 
                Country_Column.HeaderText = "France"
                Country_Column.MinWidth = 40; 
                Country_Column.FormatString = "{0:N0} Units"
                Country_Column.DataType = typeof(int); 
                Country_Column.TextAlignment = ContentAlignment.TopRight; 
                Country_Column.DecimalPlaces = 0; 
                Country_Column.Minimum = 0; 
                Country_Column.Step = 500; 
                Country_Column.ThousandsSeparator = true
                pRadGridView.MasterGridViewTemplate.Columns.Add(Country_Column); 



0
Jack
Telerik team
answered on 05 Feb 2009, 01:16 PM
Hi Fabien, thank you again for sharing your knowledge.

Hi Renu,

As Fabien said you can't group by a substring of a column. This feature will be available by using the custom grouping functionality when it is ready in one of our upcoming releases.

Currently you can only control the header text that appears in group rows. Here you can find more information on how to customize this text.

Do not hesitate to write us back if you have any other questions.
 

Kind regards,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Renu
Top achievements
Rank 1
Answers by
Prad
Top achievements
Rank 2
Renu
Top achievements
Rank 1
Fabien
Top achievements
Rank 2
Jack
Telerik team
Share this question
or