No Wrap for Grid Cell Content in Group Mode

6 posts, 0 answers
  1. Delvis
    Delvis avatar
    18 posts
    Member since:
    Mar 2012

    Posted 21 Jan 2013 Link to this post

    I have a grid with Auto Generate Columns at run time and Multi Row Selection:


    <telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowSelection="True"

           oncolumncreated="RadGrid1_ColumnCreated">

           <ClientSettings>

                 <Selecting AllowRowSelect="True" />

           </ClientSettings>

           <MasterTableView DataKeyNames="InventarioID" GroupLoadMode="Client">

                 <Columns>

                        <telerik:GridClientSelectColumn UniqueName="SelectColumn"/>

                 </Columns>

           </MasterTableView>

    </telerik:RadGrid>

    C#:

    protected void Page_Load(object sender, EventArgs e)

    {

           string _anno = StringHelpers.Right(DateTime.Today.Year.ToString(), 2);

           RadGrid1.DataSource = new DataClaseDataContext().MyTable.Select(s => new {....my fields...});

     

    }

     

    protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)

    {

           if (e.Column is GridBoundColumn)

           {

                 ((GridBoundColumn)e.Column).DataFormatString = "<nobr>{0}</nobr>";

           }

    }  


    This works well and auto adjusts the column width to content, but this functionality is lost when grouped.


    <telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowSelection="True"

                        oncolumncreated="RadGrid1_ColumnCreated">

           <ClientSettings>

                 <Selecting AllowRowSelect="True" />

           </ClientSettings>

           <MasterTableView DataKeyNames="InventarioID" GroupLoadMode="Client">

                 <Columns>

                        <telerik:GridClientSelectColumn UniqueName="SelectColumn"/>

                 </Columns>

                 <GroupByExpressions>

                        <telerik:GridGroupByExpression>

                               <SelectFields>

                                      <telerik:GridGroupByField FieldName="Area"/>

                               </SelectFields>

                               <SelectFields>

                                      <telerik:GridGroupByField FieldName="AreaDescription"

    HeaderText=" " HeaderValueSeparator="" />

                               </SelectFields>

                               <GroupByFields>

                                      <telerik:GridGroupByField FieldName="Area"/>

                               </GroupByFields>

                        </telerik:GridGroupByExpression>

                 </GroupByExpressions>

           </MasterTableView>

    </telerik:RadGrid>  


    Any help?


  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Jan 2013 Link to this post

    Hi,

    Try binding the grid using advanced data binding using its NeedDataSource event for advanced features like paging, grouping etc. Check the following help documentation which explains the same.
    Advanced Data-binding (using NeedDataSource event)

    Thanks,
    Shinu
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Delvis
    Delvis avatar
    18 posts
    Member since:
    Mar 2012

    Posted 22 Jan 2013 Link to this post

    Hi Shinu, Thanks for your reply.

    Sorry, but, how can help me that topic?. You can give me an example.

    Thanks,

    Delvis
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Jan 2013 Link to this post

    Hi,

    Try the following code.
    C#:
    protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
      {
          SqlConnection con1 = new SqlConnection(WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
          SqlCommand cmd = new SqlCommand("SELECT top 5 * FROM [Employees]", con1);
          SqlDataAdapter ad = new SqlDataAdapter(cmd);
          DataSet ds = new DataSet();
          ad.Fill(ds);
         RadGrid1.DataSource = ds;
      }

    Thanks,
    Shinu
  6. Delvis
    Delvis avatar
    18 posts
    Member since:
    Mar 2012

    Posted 23 Jan 2013 Link to this post

    Hi Shinu, Thanks for your reply.

    Sorry, my problem is not with the DataSource, the problem is when I display the grid without grouping and grouping. In the first scenario works ok, but when grouped, the columns do not fit the content.

    • Thanks,

      Delvis
  7. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 28 Jan 2013 Link to this post

    Hello Delvis,

    Please note that performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Paging, Sorting, Filtering require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
    Declarative DataSource
    Advanced Data Binding

    Also,  please try to set the tableview layout to Fixed:
    Copy Code
    Copy Code
    <MasterTableView ... TableLayout="Fixed">

    Please note that this will work only if there are spaces between the words in the text content. If a text without spaces is too long, the same issue could be observed. Basically, this is a general issue, not Telerik specific. You could check out the following article for possible approach in such a case:
    http://www.telerik.com/community/forums/aspnet-ajax/grid/how-to-wrap-the-text-without-space-in-a-rad-grid-column.aspx

    You could also try one of the following approaches to prevent the wrapping of the text content.
     First:
    Using JavaScript and resizing:
     Widest cell's content without wrapping
    You could set EnableRealTimeResize to false.
      Second:
    Copy Code
    Copy Code
    protected void RadGrid1_PreRender(object sender, EventArgs e)
        {
            RadGrid1.MasterTableView.TableLayout = GridTableLayout.Fixed;
            for (int i = 0; i < RadGrid1.MasterTableView.AutoGeneratedColumns.Length; i++)
                (RadGrid1.MasterTableView.AutoGeneratedColumns[i] as GridBoundColumn).DataFormatString = "<nobr>{0}</nobr>";
            RadGrid1.Rebind();
        }

       Third:
    Copy Code
    Copy Code
    protected void RadGrid1_PreRender(object sender, EventArgs e)
        {
            RadGrid1.ClientSettings.Resizing.AllowColumnResize = true;
            RadGrid1.ClientSettings.Resizing.ClipCellContentOnResize = true;
            RadGrid1.ClientSettings.Resizing.EnableRealTimeResize = false;
            for (int i = 0; i < RadGrid1.MasterTableView.AutoGeneratedColumns.Length; i++)
                (RadGrid1.MasterTableView.AutoGeneratedColumns[i] as GridBoundColumn).DataFormatString = "<nobr>{0}</nobr>";
            RadGrid1.Rebind();
        }

      Fourth:
    In case you have auto-generated columns.
    Copy Code
    Copy Code
    protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
        {
            RadGrid1.MasterTableView.TableLayout = GridTableLayout.Fixed;
            if (e.Column is GridBoundColumn)
            {
                (e.Column as GridBoundColumn).DataFormatString = "<nobr>{0}</nobr>";
            }
        }

    I hope this will prove helpful. If the issue remains, please elaborate on your specific scenario.

    Regards,
    Eyup
    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017