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

RadGrid - Group by brings an extra column

5 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
neeraj
Top achievements
Rank 1
neeraj asked on 28 Mar 2011, 07:13 AM
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();
            }
        }

5 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 31 Mar 2011, 09:12 AM
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
0
Mike
Top achievements
Rank 1
answered on 30 Apr 2013, 07:16 PM
Maria,

That example did not remove the blank column created at the far left when grouping.
0
Laurie
Top achievements
Rank 2
answered on 19 Jun 2013, 07:59 PM
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.
0
Maria Ilieva
Telerik team
answered on 24 Jun 2013, 09:05 AM
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.
0
Laurie
Top achievements
Rank 2
answered on 02 Jul 2013, 02:47 AM
I am not using the Filtermenu tags.  I got around the issue by throwing in an extra Rebind on the grid.
Tags
Grid
Asked by
neeraj
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Mike
Top achievements
Rank 1
Laurie
Top achievements
Rank 2
Share this question
or