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

No Wrap for Grid Cell Content in Group Mode

5 Answers 126 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Delvis
Top achievements
Rank 1
Delvis asked on 21 Jan 2013, 08:28 PM

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?


5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Jan 2013, 06:14 AM
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
0
Delvis
Top achievements
Rank 1
answered on 22 Jan 2013, 02:53 PM
Hi Shinu, Thanks for your reply.

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

Thanks,

Delvis
0
Shinu
Top achievements
Rank 2
answered on 23 Jan 2013, 05:19 AM
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
0
Delvis
Top achievements
Rank 1
answered on 23 Jan 2013, 08:49 PM
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
0
Eyup
Telerik team
answered on 28 Jan 2013, 11:21 AM
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.
Tags
Grid
Asked by
Delvis
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Delvis
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or