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

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

2 Answers 785 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Randall
Top achievements
Rank 2
Randall asked on 25 Aug 2010, 08:54 PM

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 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 26 Aug 2010, 12:08 PM
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
0
Priyanka
Top achievements
Rank 1
answered on 30 May 2014, 09:43 AM
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
Tags
Grid
Asked by
Randall
Top achievements
Rank 2
Answers by
Dimo
Telerik team
Priyanka
Top achievements
Rank 1
Share this question
or