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

Empty Field Alias in Group By Expression

7 Answers 432 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Levi
Top achievements
Rank 1
Levi asked on 06 Nov 2008, 06:34 PM
Is there any reason you can't do an empty field alias in a group by expression? This seems like a very common thing to do as the field name clutters up the group by caption. Is there any clean way to do this? Also how do i put an alias on the actual field name that shows up in the group by header. I tried adding it after the field name as you do for the first field in the expression, but this did not seem to have any effect.

Thanks!
Levi

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 07 Nov 2008, 05:49 AM
Hi Levi,

FieldAlias specifies an alias for representing the field's name.  Gets or sets a value representing a friendly name for the field used for forming the group by expression. This name will be displayed in each group header when grouping by the respective field.  The FieldAlias value cannot contain blanks or reserved characters such as ",", "." and so on. This property has a meaning only for GridGroupByField part of the SelectFields of GridGroupByExpression.

This property is useful in cases when:

    * you want to change the value displayed in group header (different than the default DataField column value)
      or
    * group by a template column and Telerik RadGrid cannot get the header text for that column.

<GroupByExpressions> 
    <telerik:GridGroupByExpression> 
     <GroupByFields> 
      <telerik:GridGroupByField   FieldName="SupplierID" FieldAlias="MyText" /> 
     </GroupByFields> 
     <SelectFields> 
      <telerik:GridGroupByField FieldName="SupplierID" FieldAlias="MyText" /> 
     </SelectFields> 
    </telerik:GridGroupByExpression> 
  </GroupByExpressions> 


Thanks
Shinu.
0
Levi
Top achievements
Rank 1
answered on 07 Nov 2008, 02:15 PM
It's obvious what a field alias is. Your answer is not helpful whatsoever. There should be an easy way to remove the field name from the group by caption. Giving me an explanation of what a field alias and it's restrictions which I already pointed out in my qusetion isn't helping anyone.
0
Shinu
Top achievements
Rank 2
answered on 10 Nov 2008, 06:27 AM
Hi Levi,

I am sorry if I have misunderstood the question. One suggestion to remove the FieldName from GridGroupHeader will be to  access the GridGroupHeader in the code behind and set the DataCell text to empty string.


CS:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridGroupHeaderItem) 
        { 
            GridGroupHeaderItem GroupHeader = (GridGroupHeaderItem)e.Item; 
            GroupHeader.DataCell.Text = string.Empty; 
        } 
    } 



Regards
Shinu
0
Levi
Top achievements
Rank 1
answered on 10 Nov 2008, 03:29 PM
That code erases the group field value as well. I want to show only the value, but not the field name. This is the only way I could find to do it, which erases the '(Showing 10 of 20)' message and the field name. It assume you data does not use : or ( symbols.

if

 

(e.Item is GridGroupHeaderItem)

 

{

 

GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;

 

 

DataRowView groupDataRow = (DataRowView)e.Item.DataItem;

 

 

 

string[] myArr = item.DataCell.Text.Split(':');

 

myArr = myArr[1].Split(

'(');

 

item.DataCell.Text = myArr[0].Trim();

}

This is definately a hack, but seems to work fine. If anyone knows a cleaner way to do this, please let me know.

Thanks,
Levi

0
Catalin
Top achievements
Rank 1
answered on 30 Mar 2011, 09:01 PM
GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;
DataRowView groupDataRow = (DataRowView)e.Item.DataItem;
item.DataCell.Text = groupDataRow.Row.ItemArray[0].ToString();

0
prens
Top achievements
Rank 1
answered on 20 Dec 2013, 01:42 PM
You can use simply (remove spaces after & and before;)
FieldAlias="& nbsp ;"
0
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
answered on 27 May 2015, 02:41 PM

FiledAlias="&nsbp;" won't work because it includes illegal characters. You have to use...

 

HeaderValueSeparator=" " HeaderText=" "  to remove the FieldAlias from the Group Header

Tags
Grid
Asked by
Levi
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Levi
Top achievements
Rank 1
Catalin
Top achievements
Rank 1
prens
Top achievements
Rank 1
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Share this question
or