Is there any way I can fix this? Also will you guys please consider changing this in the next release.
12 Answers, 1 is accepted
RadGrid header labels are by default inline text nodes. If a sort icon must be displayed and the header label occupies two lines, the sort icon will go to the second line.
I am not sure what do you mean by "both lines of the label would shift together" - the lines don't shift at all, the sort icon is added on the right side and the column width may be increased a little. If you provide some screenshots, it will be more clear. Thanks.
Best wishes,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
The labels do indeed shift. My columns will not get wider as I have them set to fixed. This behavior is different in previous versions of the DLL where both lines shifted together. Below you can see an example:
Here is how it used to work before the skins redesign. Both lines would shift together to make room for the sort symbol:
Parts ^
Sold
Now only the bottom line shifts would looks awkward:
Parts
Solid ^
Any ideas on how I can get it to work like it did in previous versions?
Thanks,
Levi
The expected behavior of the RadGrid sort indicators has always been as the one you are seeing with the current version. Probably you have used some custom approach to position the icon, which does not work any more.
If you send us a sample web page, which demonstrates the RadGrid behavior with an old version, we will help you implement the behavior with the new version.
In the meantime, I am sending you one possible approach:
| <%@ Page Language="C#" %> |
| <%@ Import Namespace="System.Data" %> |
| <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <script runat="server"> |
| protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) |
| { |
| DataTable dt = new DataTable(); |
| DataRow dr; |
| int colsNum = 10; |
| int rowsNum = 5; |
| string colName = "Column"; |
| for (int j = 1; j <= colsNum; j++) |
| { |
| dt.Columns.Add(String.Format("{0}{1} {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} {0}{1}", colName, k)] = String.Format("{0}{1} Row{2}", colName, k, i); |
| } |
| dt.Rows.Add(dr); |
| } |
| (sender as RadGrid).DataSource = dt; |
| } |
| </script> |
| <html xmlns="http://www.w3.org/1999/xhtml" > |
| <head runat="server"> |
| <meta http-equiv="content-type" content="text/html;charset=utf-8" /> |
| <title>RadControls for ASP.NET AJAX</title> |
| <style type="text/css"> |
| .RadGrid .rgHeader a |
| { |
| float:left; |
| width:1px; |
| } |
| .RadGrid .rgHeader .rgSortAsc, |
| .RadGrid .rgHeader .rgSortDesc |
| { |
| float:right; |
| } |
| .RadGrid .rgHeader .rgSortAsc, |
| .RadGrid .rgHeader .rgSortDesc |
| { |
| margin-top:10px; |
| } |
| *+html .RadGrid .rgHeader .rgSortAsc, |
| *+html .RadGrid .rgHeader .rgSortDesc |
| { |
| margin-top:-5px; |
| } |
| * html .RadGrid .rgHeader .rgSortAsc, |
| * html .RadGrid .rgHeader .rgSortDesc |
| { |
| margin-top:-5px; |
| } |
| </style> |
| </head> |
| <body> |
| <form id="form1" runat="server"> |
| <asp:ScriptManager ID="ScriptManager1" runat="server" /> |
| <telerik:RadGrid |
| ID="RadGrid1" |
| runat="server" |
| Skin="Office2007" |
| Width="900px" |
| AllowSorting="true" |
| OnNeedDataSource="RadGrid_NeedDataSource"> |
| <MasterTableView TableLayout="Fixed"> |
| <SortExpressions> |
| <telerik:GridSortExpression FieldName="Column2 Column2" /> |
| </SortExpressions> |
| </MasterTableView> |
| </telerik:RadGrid> |
| </form> |
| </body> |
| </html> |
Best wishes,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Thanks for this, although I have my labels right aligned, so this approach wouldn't work for me. Any ideas? I got this to somewhat work, although the sort symbol does not vertically center with the label:
| <telerik:GridBoundColumn UniqueName="PurchaseAssists" DataFormatString="{0:#,0}" |
| SortExpression="PurchaseAssists" HeaderText="<div align='right' style='display:inline-block'>Purchase<br/>Assists</div>" DataField="PurchaseAssists" |
| ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right"> |
| <HeaderStyle></HeaderStyle> |
| </telerik:GridBoundColumn> |
I tried using float, but wouldn't work. Inline-block was the only way I could keep the sort symbol on the right side or prevent it from moving down to the next line. Also I don't think inline-block is fully supported by all browsers. I'd prefer to just modify the grid classes though, without messing up the columns I have left aligned. Maybe that's not possible. Your help is appreciated.
Thanks,
Levi
The solution provided above is the best thing I can offer you by using native RadGrid CSS classes only and not modifying the header HTML.
Modifying the header HTML (your approach) is also a viable option, so feel free to use it according to your preference.
As I said, if you have had the RadGrid control behave as expected with the old version, show us how you did it and what difficulties you have implementing the same approach with the latest version.
Regards,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Unfortunately I'm still getting the same behavior with both older and newer version of RadGrid. Can you please check the attached page and let me know if I'm missing something obvious.
Greetings,
Rosen
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Thanks,
Levi
In this situation I suggest you to adjust the column widths, so that the header text and sorting icon fit on a single line. You may need to enable RadGrid scrolling. We can consider modifying the control's rendering in the future.
Regards,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Here is a solution for anyone is interested.
First add the following css class:
<style type="text/css">
.inlinebox
{
display: -moz-inline-stack;
display: inline-block;
vertical-align: middle;
zoom: 1;
*display:inline;
}
</style>
Then for your double line headings do the following for the header text:
<telerik:GridBoundColumn ... ... HeaderText="<span class='inlinebox'>Two</br>Lines</span>"> |
| </telerik:GridBoundColumn> |
Two caveats.. It causes single line labels to shift downward. I think it's some issue with line height, because it works perfect with multi-line labels. Also, if you're using fixed column widths, you'll want to explicitly use "<br/>" to break up the lable. Otherwise display block causes it to fill the whole width of the heading. I get around this by checking for "<br>" before wrapping the label with a span. If anyone finds a better solution, please let me know.
BTW, I tried just modifying the grid skin, but this won't work on firefox. You have to physically add a span around the label. I added an event handler to do this automatically. I loop through all the RadGrids on my page then execute the following code:
protected virtual void FixGridColumns(telerik.RadGrid grid)
{
foreach (telerik.GridColumn col in grid.MasterTableView.RenderColumns)
{
if (!col.HeaderText.Contains("</span>") && col.HeaderText.Contains("<br")) // prevent editing on follow-up requests and ensure it's a double line label
col.HeaderText =
"<span class='inlinebox'>" + col.HeaderText + "</span>";
}
}
