Empty Field Alias in Group By Expression

8 posts, 0 answers
  1. Levi
    Levi avatar
    134 posts
    Member since:
    Jul 2008

    Posted 06 Nov 2008 Link to this post

    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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Nov 2008 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Levi
    Levi avatar
    134 posts
    Member since:
    Jul 2008

    Posted 07 Nov 2008 Link to this post

    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.
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Nov 2008 Link to this post

    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
  6. Levi
    Levi avatar
    134 posts
    Member since:
    Jul 2008

    Posted 10 Nov 2008 Link to this post

    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

  7. Catalin
    Catalin avatar
    7 posts
    Member since:
    Mar 2011

    Posted 30 Mar 2011 Link to this post

    GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;
    DataRowView groupDataRow = (DataRowView)e.Item.DataItem;
    item.DataCell.Text = groupDataRow.Row.ItemArray[0].ToString();

  8. prens
    prens avatar
    4 posts
    Member since:
    Feb 2007

    Posted 20 Dec 2013 Link to this post

    You can use simply (remove spaces after & and before;)
    FieldAlias="& nbsp ;"
  9. Albert Shenker
    Albert Shenker avatar
    550 posts
    Member since:
    Mar 2004

    Posted 27 May 2015 in reply to prens Link to this post

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

     

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

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017