|
| 1 | +--- |
| 2 | +title: Disable Label Wrapping in the Grid Popup Edit Form |
| 3 | +description: How to prevent label text wrapping in the popup editor of the Grid and TreeList. |
| 4 | +type: how-to |
| 5 | +page_title: Disable Label Wrapping in the Grid Popup Edit Form |
| 6 | +slug: grid-popup-edit-form-disable-label-wrapping |
| 7 | +position: |
| 8 | +tags: grid,popup,edit,form,label,wrap |
| 9 | +ticketid: 1544767 |
| 10 | +res_type: kb |
| 11 | +--- |
| 12 | + |
| 13 | +## Environment |
| 14 | + |
| 15 | +<table> |
| 16 | + <tbody> |
| 17 | + <tr> |
| 18 | + <td>Product</td> |
| 19 | + <td> |
| 20 | + Form for Blazor, <br /> |
| 21 | + Grid for Blazor, <br /> |
| 22 | + TreeList for Blazor |
| 23 | + </td> |
| 24 | + </tr> |
| 25 | + </tbody> |
| 26 | +</table> |
| 27 | + |
| 28 | + |
| 29 | +## Description |
| 30 | + |
| 31 | +How to prevent text wrapping inside the Grid popup edit form? My column names are long and contain several words. They cannot fit on a single line and wrap. |
| 32 | + |
| 33 | + |
| 34 | +## Solution |
| 35 | + |
| 36 | +There are two ways to ensure that long form labels fit on a single line in the popup. Both techniques use **CSS**. The required code is identical for Grids and TreeLists. |
| 37 | + |
| 38 | +* Increase the popup edit form width: |
| 39 | + |
| 40 | + ````css |
| 41 | + .k-window .k-form-horizontal { |
| 42 | + min-width: 600px; |
| 43 | + } |
| 44 | + ```` |
| 45 | + |
| 46 | +* Prevent text wrapping of the form labels: |
| 47 | + |
| 48 | + ````css |
| 49 | + .k-window .k-form-horizontal .k-form-label { |
| 50 | + white-space: nowrap; |
| 51 | + margin-left: 10px; |
| 52 | + } |
| 53 | + ```` |
| 54 | + |
| 55 | +> If you place the above CSS rules in the global app stylesheet (usually `site.css`), they will affect **all** popup forms in the app. To avoid this, keep the CSS code in the Razor file, which defines the edit form. [CSS isolation (scoped styles)]({%slug common-kb-css-isolation%}) will not work, because the Window is rendered as a child of the page `<body>`, i.e. outside the Razor component. |
| 56 | +> |
| 57 | +> For full control of the edit form layout and more advanced customizations, you can also use a [custom edit form in a separate TelerikWindow](https://github.com/telerik/blazor-ui/tree/master/grid/custom-popup-form). |
| 58 | + |
| 59 | + |
| 60 | +## Example |
| 61 | + |
| 62 | +>caption Prevent label wrapping in popup edit forms |
| 63 | + |
| 64 | +````CSHTML |
| 65 | +@* Prevent label wrapping in popup edit forms *@ |
| 66 | + |
| 67 | +<style> |
| 68 | + /* normally, only one of these CSS rules is enough */ |
| 69 | + |
| 70 | + .k-window .k-form-horizontal { |
| 71 | + /* min-width: 600px; */ |
| 72 | + } |
| 73 | + |
| 74 | + .k-window .k-form-horizontal .k-form-label { |
| 75 | + white-space: nowrap; |
| 76 | + margin-left: 10px; |
| 77 | + } |
| 78 | +</style> |
| 79 | + |
| 80 | +<TelerikGrid Data=@GridData EditMode="@GridEditMode.Popup"> |
| 81 | + <GridColumns> |
| 82 | + <GridColumn Field=@nameof(Product.Name) Title="Product Name" /> |
| 83 | + <GridColumn Field=@nameof(Product.Quantity) Title="Units in Stock" /> |
| 84 | + <GridCommandColumn Width="120px"> |
| 85 | + <GridCommandButton Command="Edit" Icon="edit">Edit</GridCommandButton> |
| 86 | + </GridCommandColumn> |
| 87 | + </GridColumns> |
| 88 | +</TelerikGrid> |
| 89 | + |
| 90 | +@code { |
| 91 | + public List<Product> GridData { get; set; } |
| 92 | + |
| 93 | + protected override void OnInitialized() |
| 94 | + { |
| 95 | + GridData = new List<Product>(); |
| 96 | + |
| 97 | + for (int i = 1; i <= 5; i++) |
| 98 | + { |
| 99 | + GridData.Add(new Product() |
| 100 | + { |
| 101 | + ID = i, |
| 102 | + Name = $"Product Name {i}", |
| 103 | + Quantity = i |
| 104 | + }); |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + public class Product |
| 109 | + { |
| 110 | + public int ID { get; set; } |
| 111 | + public string Name { get; set; } |
| 112 | + public int Quantity { get; set; } |
| 113 | + } |
| 114 | +} |
| 115 | +```` |
0 commit comments