RadGrid - Group by brings an extra column

6 posts, 0 answers
  1. neeraj
    neeraj avatar
    1 posts
    Member since:
    Mar 2011

    Posted 28 Mar 2011 Link to this post

    Hi There,

    i am using Radgrid for displaying records in groups. i have set group by filed in code behind - under Initialize method in my Code(Below).i am hiding some of the columns (that i do not intend to display) in ItemDataBound method.
    Now the problem is it brings an extra column in the view that i am not able to remove.i have attached the screenshot of the Radgrid for reference.

    please help.
    Thanks in advance.
    - Neeraj

     

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="QuestionResponseTableView.ascx.cs"
        Inherits="CEB.CLC.Reporting.GenView.UserControls.QuestionResponseTableView" %>
    <%@ Register Src="~/UserControls/ExportData.ascx" TagName="ExportData" TagPrefix="ucl" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <div id="expDiv" runat="server" class="text-right z-index-0">
        <ucl:ExportData EnableViewState="true" ID="edQuestionResponse" runat="server" />
    </div>
    <div class="clear">
    </div>
    <div id="dvOuter" runat="server">
        <div id="dvContent" runat="server">
            <asp:Panel ID="pnlContent" runat="server" CssClass="graphviewposition">
                <div class="tablelink" id="dvGrid" runat="server">
                    <telerik:RadGrid AlternatingItemStyle-CssClass="even" ID="radGridQuestion" OnItemCreated="radGridQuestion_ItemCreated"
                        OnColumnCreated="radGridQuestion_ColumnCreated" OnItemDataBound="radGridQuestion_ItemDataBound"
                        runat="server" AutoGenerateColumns="true" GridLines="none">
                        <MasterTableView GroupsDefaultExpanded="true">
                            <GroupByExpressions>
                                <telerik:GridGroupByExpression>
                                    <SelectFields>
                                    </SelectFields>
                                    <GroupByFields>
                                    </GroupByFields>
                                </telerik:GridGroupByExpression>
                            </GroupByExpressions>
                        </MasterTableView>
                        <ClientSettings>
                            <Resizing ResizeGridOnColumnResize="false" AllowColumnResize="true" />
                        </ClientSettings>
                    </telerik:RadGrid>
                </div>
            </asp:Panel>
            <div class="clear">
            </div>
        </div>
    </div>

    public void Initialize(IReportDataView inputData, ReportDTO report, PageInfo pageInfo)
            {
                if (!base.DisplayExportHeader)
                {
                    edQuestionResponse.Visible = false;
                }
      
                //setting GroupBy field name from Resource file 
                string groupByFieldName = base.GetResxString("Col_ItemText", ComparisonViewRESX.Col_ItemText).Replace(" ", "");
      
                if (this.radGridQuestion.MasterTableView.GroupByExpressions[0].SelectFields.Count == 0)
                {
                    this.radGridQuestion.MasterTableView.GroupByExpressions[0].SelectFields.Add(new GridGroupByField() { FieldName = groupByFieldName });
                    this.radGridQuestion.MasterTableView.GroupByExpressions[0].GroupByFields.Add(new GridGroupByField() { FieldName = groupByFieldName, SortOrder = GridSortOrder.Ascending });
                }
      
                DataTable dtFrequencyData = inputData.GetView();
                radGridQuestion.DataSource = dtFrequencyData.DefaultView;
                radGridQuestion.DataBind();
      
                if (EnableHyperLink && report.ReportParameters.QuestionResponseViewType != CEB.CLC.Reporting.Core.Enum.ViewType.DoNotShow)
                {
                    dvContent.Attributes.Add("onmouseover", "this.style.cursor='pointer'");
                    dvContent.Attributes.Add("onClick", "javascript:TransferTablePath(" + DataViewId + " )");
                }
      
                edQuestionResponse.TableView = dtFrequencyData;
                edQuestionResponse.ExportDataViewStyle = DataViewStyleEnum.QuestionResponse;
      
                ViewState["FrequencyData"] = dtFrequencyData;
            }
      
    protected void radGridQuestion_ItemDataBound(object sender, GridItemEventArgs e)
            {
                foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
                {
      
                    if (column.UniqueName == "ItemId")
                    {
                        column.Visible = false;
                    }
      
                }
                if (e.Item is GridDataItem)
                {
                    GridDataItem dataItem = e.Item as GridDataItem;
                    dataItem[base.GetResxString("Col_ItemText", ComparisonViewRESX.Col_ItemText)].Text = String.Empty;
                }
                else if (e.Item is GridHeaderItem)
                {
                    RadGrid objGridView = sender as RadGrid;
                    DataView objDataView = objGridView.DataSource as DataView;
                    DataTable objDataTable = objDataView.Table;
                    foreach (DataColumn col in objDataTable.Columns)
                    {
                        int index = objDataTable.Columns.IndexOf(col);
                        if (e.Item.Cells[index + 3].HasControls())
                        {
                            LiteralControl columnName = (LiteralControl)e.Item.Cells[index + 3].Controls[0];
                            columnName.Text = col.Caption;
                        }
                    }
                }
                else if (e.Item is GridGroupHeaderItem)
                {
                    GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;
                    DataRowView groupDataRow = (DataRowView)e.Item.DataItem;
                    item.DataCell.Text = groupDataRow[base.GetResxString("Col_ItemText", ComparisonViewRESX.Col_ItemText)].ToString();
      
                }
      
            }
      
            protected void radGridQuestion_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
            {
                if (e.Column is GridGroupSplitterColumn)
                {
                    e.Column.HeaderStyle.Width = Unit.Pixel(1);
                    e.Column.ItemStyle.Width = Unit.Pixel(1);
                    e.Column.Resizable = false;
                }
            }
      
            protected void radGridQuestion_ItemCreated(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridGroupHeaderItem)
                {
                    (e.Item as GridGroupHeaderItem).Cells[0].Controls.Clear();
                }
            }
  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 31 Mar 2011 Link to this post

    Hi,

    The new column that is added is the group expand collapse column and it is expected to appear when grouping is used. Please see the following online example which has the same behavior when group by expressions is used.




    Kind regards,
    Maria Ilieva
    the Telerik team
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mike
    Mike avatar
    338 posts
    Member since:
    Jun 2008

    Posted 30 Apr 2013 Link to this post

    Maria,

    That example did not remove the blank column created at the far left when grouping.
  5. Laurie
    Laurie avatar
    141 posts
    Member since:
    Feb 2007

    Posted 19 Jun 2013 Link to this post

    I agree with Mike.  I have a column that shows up when the grid is first loaded, as can be seen in Grid1.png, attached, but disappears as soon as a Reload() happens, as in Grid2.png. I need to get rid of this column entirely.
  6. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 24 Jun 2013 Link to this post

    Hi,

    I suppose that the issue you are facing is related to the problem we have discovered in the latest official Q2 2013 release and which is described in the sticky thread below:
    http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-layout-breaks-on-postback-in-q2-2013-release.aspx

    Review the thread and verify if removing the problematic <FilterMenu></FilterMenu> tags helps.

    Regards,
    Maria Ilieva
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  7. Laurie
    Laurie avatar
    141 posts
    Member since:
    Feb 2007

    Posted 01 Jul 2013 Link to this post

    I am not using the Filtermenu tags.  I got around the issue by throwing in an extra Rebind on the grid.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017