How do I wrap contents of long text in a RadGrid column?

3 posts, 0 answers
  1. Randall
    Randall avatar
    54 posts
    Member since:
    Jun 2008

    Posted 25 Aug 2010 Link to this post

    Hello,

    I have a RadGrid (v2009.01.0527.20) with Height=”100%” and Width=”100” that is inside a RadSplitter pane and set to automatically resize with the RadSplitter pane resize.  This is based on the demo code from:

    http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandsplitterresizing/defaultcs.aspx?product=grid.

    The columns are NOT autogenerated, they are GridBoundColumn and a few of my own custom columns that inherits GridBoundColumn and are used for custom filtering.

    All this is working fine so far.

    My problem is that some of the text column contents are too long to fit in the column and do not wrap but instead bleed over into the next adjacent column.  I have tried adding ClientSettings-Resizing-ClipCellContentOnResize="true" but that does not work, the text still bleeds over into the next adjacent column.

    How do I get the cell contents to wrap when it is too long to fit in column?

    Thanks,

    Randall Price

  2. Dimo
    Admin
    Dimo avatar
    8330 posts

    Posted 26 Aug 2010 Link to this post

    Hi Randall,

    Due to cross-browser differences, you can force long words to wrap (break) only in Internet Explorer. For other browsers the only thing you can do is clip the non-fitting content or use wider columns.

    Here is a simple demo:

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
     
    <script runat="server">
     
        protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            DataTable dt = new DataTable();
            DataRow dr;
            int colsNum = 4;
            int rowsNum = 6;
            string colName = "Column";
     
            for (int j = 1; j <= colsNum; j++)
            {
                dt.Columns.Add(String.Format("{0}{1}", colName, j));
            }
     
            for (int i = 1; i <= rowsNum; i++)
            {
                dr = dt.NewRow();
     
                for (int k = 1; k <= colsNum; k++)
                {
                    dr[String.Format("{0}{1}", colName, k)] = String.Format("{0}{1}Row{2}", colName, k, i);
                }
                dt.Rows.Add(dr);
            }
     
            (sender as RadGrid).DataSource = dt;
        }
         
    </script>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     
    <head runat="server">
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <title>RadControls</title>
    <style type="text/css">
     
    .RadGrid
    {
        /*works in IE*/
        word-break:break-all;
    }
     
    .RadGrid td
    {
        /*works in Firefox*/
        overflow:hidden;
    }
     
    </style>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
     
    <telerik:RadGrid
        ID="RadGrid1"
        runat="server"
        Width="300px"
        OnNeedDataSource="RadGrid_NeedDataSource">
        <MasterTableView TableLayout="Fixed" />
    </telerik:RadGrid>
     
    </form>
    </body>
    </html>

    Kind regards,
    Dimo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Priyanka
    Priyanka avatar
    1 posts
    Member since:
    May 2014

    Posted 30 May 2014 in reply to Dimo Link to this post

    Hi - I tried this and it worked for me. 
    Your page width has to be dynamic as per number of columns selected for display. I am incrementing by 1 just to increase few more pixels.
    200 represents column width in pixels. My column data do not exceed this size.

    GridToExport.ExportSettings.Pdf.PageWidth = (GridToExport.MasterTableView.AutoGeneratedColumns.Count + 1) * 200
Back to Top