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

[Solved] Radgrid resizing the wrong column

3 Answers 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Keith
Top achievements
Rank 1
Keith asked on 25 Mar 2013, 04:53 PM
I have a dynamic grid that is able to change column widths and adjusts the grid's size to accommodate the grid size changes. However, when the user goes to drag a column, the column they are trying to select is not re-sized and instead another column (it changes from datasource to datasource) usually 1 or 2 columns to the right is re-sized instead. The only 2 columns that work as intended are the edit/delete columns which are hard coded into the grid. There is also a hidden column hard coded after the edit/delete columns as well that is required in certain places. Also, a few of the datasources use grouping. We are currently using version 2012.1.411 and do not have the option to update at this time. Below are the current radgrid settings we are using and I attached a screenshot to show the issue.
(in the screenshot I tried re-sizing "Total Acres" and instead it re-sized "Non Federal Acres" 2 columns over)

troubleshooting: I tried removing the hidden column and it did not affect the issue

current grid settings:
AutoGenerateColumns="true"
<GroupingSettings ShowUnGroupButton="true" CaseSensitive="false" />
<ClientSettings AllowDragToGroup="true" AllowColumnsReorder="true">
            <Selecting AllowRowSelect="true" />           
            <
Resizing AllowColumnResize="true" EnableRealTimeResize="true" ResizeGridOnColumnResize="true" />          
            <
Scrolling SaveScrollPosition="false" AllowScroll="false" />
            <ClientEvents OnPopUpShowing="PopUpShowing" />
</ClientSettings>

3 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 28 Mar 2013, 12:39 PM
Hi,

 Can you please elaborate a little bit more on the actual markup of the grid and how you populate the control with data as well as any other specific logic in code behind (how you bind it, whether you add remove columns dynamically, etc). Normally the control should not experience such issues unless there is some other custom code that interferes with the indexes of the columns. Providing the full markup and code behind for the grid can help us to replicate the issue and let you know how it can be resolved.

Greetings,
Marin
the Telerik team
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 their blog feed now.
0
Keith
Top achievements
Rank 1
answered on 28 Mar 2013, 03:51 PM
I'll provide as much as I can, also this grid is being used in a sharepoint website if that makes a difference:
(note: for "EditFormSettings-UserControlName" we assign a default usercontrol but I have removed it here as the path has some sensitive information)

Markup for Grid:
<telerik:RadGrid ID="rgDynamic" runat="server" OnNeedDataSource="rgDynamic_OnNeedDataSource"
                        OnItemDataBound="rgDynamic_ItemDataBound" OnItemCommand="rgDynamic_ItemCommand"
                        PageSize="10" AllowSorting="true" AllowPaging="true" EnableLinqExpressions="false"
                        ShowGroupPanel="true" AllowMultiRowSelection="false" EnableHeaderContextMenu="true"
                        AllowFilteringByColumn="true" AutoGenerateColumns="true" EnableHeaderContextFilterMenu="true"
                        Visible="false" OnColumnCreated="rg_ColumnCreated" OnExcelExportCellFormatting="rg_ExcelExportCellFormatting"
                        OnPreRender="rg_PreRender" OnItemCreated="rgDynamic_ItemCreated">
                        <MasterTableView EditMode="PopUp" AllowMultiColumnSorting="true" CommandItemDisplay="None"
                            InsertItemPageIndexAction="ShowItemOnCurrentPage">
                            <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" Position="Top" />
                            <CommandItemSettings ShowRefreshButton="false" ShowAddNewRecordButton="true" ShowExportToCsvButton="true"
                                ShowExportToExcelButton="true" ShowExportToPdfButton="false" ShowExportToWordButton="true" />
                            <EditFormSettings EditFormType="WebUserControl">
                                <PopUpSettings Modal="true" Width="950px" Height="450px" ScrollBars="Auto" ZIndex="5000"
                                    CloseButtonToolTip="Close form and cancel any changes" />
                                <EditColumn UniqueName="editCommandColumn" ButtonType="ImageButton">
                                </EditColumn>
                            </EditFormSettings>
                            <Columns>
                                <telerik:GridEditCommandColumn HeaderText="Edit" ButtonType="ImageButton" UniqueName="EditForm">
                                    <HeaderStyle Width="50px" HorizontalAlign="Center" />
                                    <ItemStyle Width="50px" HorizontalAlign="Center" />
                                </telerik:GridEditCommandColumn>
                                <telerik:GridButtonColumn HeaderText="Remove" ButtonType="ImageButton" UniqueName="DeleteCol"
                                    Visible="false" CommandName="Delete" ConfirmText="Are you sure you want to remove this? This action cannot be undone.">
                                    <HeaderStyle Width="60px" HorizontalAlign="Center" />
                                    <ItemStyle Width="60px" HorizontalAlign="Center" />
                                </telerik:GridButtonColumn>
                                <telerik:GridTemplateColumn HeaderText="Final Report" UniqueName="Finalreport"
                                    Visible="false">
                                    <ItemTemplate>
                                                      <%--not functional, work in progress --%>
                                       Document Not Found
                                    </ItemTemplate>
                                      <HeaderStyle Width="120px"/>
                                    <ItemStyle Width="120px"/>
                                </telerik:GridTemplateColumn>
                            </Columns>
                        </MasterTableView>
                        <GroupingSettings ShowUnGroupButton="true" CaseSensitive="false" />
                        <ClientSettings AllowDragToGroup="true" AllowColumnsReorder="true">
                            <Selecting AllowRowSelect="true" />
                            <Resizing AllowColumnResize="true" EnableRealTimeResize="true" ResizeGridOnColumnResize="true" />
                            <Scrolling SaveScrollPosition="false" AllowScroll="false" />
                            <ClientEvents OnPopUpShowing="PopUpShowing" />
                        </ClientSettings>
                        <ExportSettings ExportOnlyData="true" IgnorePaging="true" HideStructureColumns="true"
                            OpenInNewWindow="true">
                        </ExportSettings>
                    </telerik:RadGrid>

Code Behind Methods:
   protected void rgDynamic_OnNeedDataSource(object o, GridNeedDataSourceEventArgs e)
        {
            if (!rgDynamic.Visible)
                return;
             
           Entities data = new Entities();
            int key = getKey();
 
            if (key > 0)
            {
                  //note: this is an example of how we assign all our datasources for this grid
                  string selectedMenu = getSelectedMenu();
 
                //sets up up a delete column specific to the edit page
                try
                {
                    GridColumn del = rgDynamic.Columns.FindByUniqueName("DeleteCol");
                    del.Visible = false;
                }
                catch
                {
                }
 
//chooses datasource to assign based upon user's selections on an external menu
                switch (selectedMenu)
                {
                    case "DataSource":
                            var DataSource = (from p in data.Table
                                   where p.Key == key
                                   select
                            new
                            {
                                BookID = p.BookID,
                                Entry = p.Entry,
                                Page = p.Page,
                                Number = p.Number,
                                Status = p.Status,
                                Action = p.Action
                           });
                        rgDynamic.DataSource = DataSource;
                        rgDynamic.MasterTableView.EditFormSettings.UserControlName = "~/ControlTemplates/EditDataSource.ascx";
 
                        rgDynamic.MasterTableView.DataKeyNames = new string[1] { getDataKeyName() };
 
                        ShowAdminControls("Are you sure you want to delete this? This action cannot be undone.", true, false);
                       
                        break;
                        //other similar case statements
                    }
                 rgDynamic.MasterTableView.CommandItemSettings.AddNewRecordText = "Create new " + selectedMenu;
            }
}

public void rg_PreRender(object o, EventArgs e)
        {
            RadGrid rg = (RadGrid)o;
            if (rg.Items.Count <= 0)
            {
                ////no data to display
                rg.MasterTableView.PagerStyle.AlwaysVisible = false;
                rg.MasterTableView.Width = Unit.Pixel(500);
            }
            else
            {
                rg.MasterTableView.PagerStyle.AlwaysVisible = true;
                rg.MasterTableView.Width = Unit.Percentage(100);
            }
//other code that grabs and shows currently selected filters to user in a label
}

protected void rg_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
      {
          //Default settings for all columns
          e.Column.FilterControlWidth = Unit.Percentage(50);
          e.Column.AutoPostBackOnFilter = true;
          e.Column.CurrentFilterFunction = GridKnownFunction.Contains;
          e.Column.ItemStyle.Width = Unit.Pixel(100);
          e.Column.HeaderStyle.Width = Unit.Pixel(100);
 
          string colName = e.Column.UniqueName.ToUpper();
          if (colName == "BackgroundNumberData")//not the actual column names we're looking for
          {
              e.Column.Display = false;
          }
          else if (colName == "MoreDataSpecificColumnNames")//not the actual column names we're looking for
        
{
              e.Column.Display = false;
          }
          else if (colName.EndsWith("ID"))
          {
              //hide all ID columns
              e.Column.Display = false;
          }
          if (colName.Contains("MEMO")
              || colName.Contains("DESCRIPTION")
              || colName.Contains("COMMENT"))
          {
              //make comment/memo/description fields wider
              e.Column.ItemStyle.Width = Unit.Pixel(250);
              e.Column.HeaderStyle.Width = Unit.Pixel(250);
          }
          else if (e.Column.DataType.ToString() == "System.DateTime")
          {
              //change format of date columns and change the default filter function
              e.Column.CurrentFilterFunction = GridKnownFunction.GreaterThanOrEqualTo;
              ((GridBoundColumn)e.Column).DataFormatString = "{0:MM/dd/yyyy}";
              e.Column.FilterControlWidth = Unit.Percentage(55);
              e.Column.ItemStyle.Width = Unit.Pixel(125);
              e.Column.HeaderStyle.Width = Unit.Pixel(125);
          }
          else if (e.Column.DataType.ToString() == "System.Boolean")
          {
              //change width of checkbox columns and change the default filter function
              e.Column.CurrentFilterFunction = GridKnownFunction.EqualTo;
              e.Column.ItemStyle.Width = Unit.Pixel(80);
              e.Column.HeaderStyle.Width = Unit.Pixel(80);
          }
      }

I excluded a few methods but none of the code inside those methods deal with columns or the radgrid.
0
Marin
Telerik team
answered on 01 Apr 2013, 08:58 AM
Hi,

 Thank you for the provided sample code. I tested a page based on the same code (using version 2012.1.411) but could not replicate the described issue. You can find attached the sample page. Another thing that you can check is whether there is any additional code that shows or hides the columns of the grid which can cause issues with the resizing. And also if the problem appears when the grid has no hidden columns. Other than that I do not see any problems in the code that can lead to this behavior.

Kind regards,
Marin
the Telerik team
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 their blog feed now.
Tags
Grid
Asked by
Keith
Top achievements
Rank 1
Answers by
Marin
Telerik team
Keith
Top achievements
Rank 1
Share this question
or