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

[Solved] Column header text wrap

4 Answers 665 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alex
Top achievements
Rank 1
Alex asked on 06 Jul 2010, 10:32 PM
Hi,

Is there a way to wrap the text in a grid's column header? The text in data bound cells wraps just fine, however I can't get the same working in the table headers. Any suggestions?

Thanks,

Alex

4 Answers, 1 is accepted

Sort by
0
dizzwave
Top achievements
Rank 1
answered on 25 Mar 2011, 09:52 PM
Hi Alex,
Have you figured out the answer to this one yet? I too would love to know.

thanks,
dave
0
Alex
Top achievements
Rank 1
answered on 28 Mar 2011, 03:16 PM
You can achive this using stylesheet, something like:
.wrappableHeader
{
    white-space: normal;
    height: 50px;
    overflow: hidden;
    vertical-align: top;
}
0
Scott
Top achievements
Rank 2
answered on 01 Aug 2011, 07:40 PM

I had the same question, and through a few different answers in the forum I settled with this...

I pass my model in to the view to get the columns setup, but use an Ajax databinding call to actually populate the data. This gives you your columns right away, even though data hasn't loaded yet.  Important for the javascript to come.

<%= Html.Telerik().Grid<Bpa.Transmission.Administration.Models.Logging_Log>()
 .Name("LogGrid")
 .Columns(columns =>
 {
     columns.Bound(o => o.Message_Txt).Title("Message");
     columns.Bound(o => o.Short_Message_Txt).Title("Short Message");
     columns.Bound(o => o.Created_Dttm).Title("Date Created").Width(30).Format("{0:MM/dd/yyyy}");
     columns.Bound(o => o.Agent_Nm).Title("Agent").Width(60);
 })
 .DataBinding(dBinding => dBinding.Ajax().Select("_SelectClientSide", "Log", new { id = ViewData["agent"] }))
 .Pageable()
%>


Setup a javascript function to be called when the page is done loading. 

<% Html.Telerik()
   .ScriptRegistrar()
   .OnDocumentReady(() =>
        {%>
        ReformatGrid();
        <%}
); %>


Put the javascript function anywhere, doesn`t matter where

<script type="text/javascript">
  
      function ReformatGrid() {
          var value = $('#LogGrid th:eq(4)').html();
          value = value.replace('Date Created', 'Date <br>Created');
          $('#LogGrid th:eq(4)').html(value);
          value = $('#LogGrid th:eq(3)').html();
          value = value.replace('Short Message', 'Short <br>Message');
          $('#LogGrid th:eq(3)').html(value);
        }
</script>

 

This does depend on knowing the position of a column (zero based).  This is a problem when column order is dynamic.  Couldn't find a way to do this by name, just by ordinal position.

To make sure things stay pretty add this to the header content area of your View page, this adds to existing style values.
Note: em should be used to avoid display resolution difference issues.

<asp:content ID="Content3" contentplaceholderid="HeaderContent" runat="server">
    <style type="text/css">
    /* additional style for multi-line headers, use 3 for two line headers */
    th
    {
        height:3em;
        vertical-align:top;
    }               
  </stytle>
</asp:content>

 

That's it.  Now your header wraps where you expect it to.

I hope they change this in a future build, this seems like a pretty big club to use.

0
Kev
Top achievements
Rank 1
answered on 10 Aug 2011, 07:48 PM
This thread addresses the problem in a much more efficient manner.

http://www.telerik.com/community/forums/aspnet-mvc/general/how-to-wrap-column-text-of-grid-asp-net-mvc2.aspx
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
dizzwave
Top achievements
Rank 1
Alex
Top achievements
Rank 1
Scott
Top achievements
Rank 2
Kev
Top achievements
Rank 1
Share this question
or