Skip to content

Commit beeba2a

Browse files
firozmangroedimodi
andcommitted
Update grid-rows-text-ellipsis.md (#1548)
* Update grid-rows-text-ellipsis.md In case you need to render all cells and do not want to do it column by column * docs(grid): Apply custom column and row styles to separate Grid instances --------- Co-authored-by: Dimo Dimov <961014+dimodi@users.noreply.github.com>
1 parent dd355c0 commit beeba2a

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

knowledge-base/grid-rows-text-ellipsis.md

+41-16
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ You might still want to allow the user to see the whole content, so you can enab
3535

3636

3737
````CSHTML
38-
@*Use the OnCellRender event to pass a custom CSS class to the Grid column and prevent it from wrapping the text in multiple lines for the Notes column. Display the full content of the column in a separate Window component.*@
39-
40-
Resize Note column or double click on a row to see the product details
41-
42-
<TelerikGrid Data="@MyData" Height="400px"
43-
Pageable="true" Sortable="true" Groupable="true"
44-
FilterMode="Telerik.Blazor.GridFilterMode.FilterRow"
38+
@*Use the OnCellRender event to pass a custom CSS class to the Grid column and prevent it from wrapping the text in multiple lines for the Notes column. Display the full content of the column in a separate Window component.
39+
Use the OnRowRender event to set a custom CSS class to Grid rows.*@
40+
41+
Both Grids have column resizing enabled. Double click a row to see the full Notes value.
42+
<br />
43+
Ellipsis for the Notes column via OnCellRender.
44+
<TelerikGrid Data="@MyData" Height="300px"
45+
Pageable="true" Sortable="true"
4546
Resizable="true" Reorderable="true"
4647
OnRowDoubleClick="@OnRowDoubleClickHandler">
4748
<GridColumns>
@@ -61,11 +62,30 @@ Resize Note column or double click on a row to see the product details
6162
</GridColumns>
6263
</TelerikGrid>
6364
65+
Ellipsis for all columns via OnRowRender.
66+
67+
<TelerikGrid Data="@MyData" Height="300px"
68+
Pageable="true" Sortable="true"
69+
Resizable="true" Reorderable="true"
70+
OnRowDoubleClick="@OnRowDoubleClickHandler"
71+
OnRowRender="@OnRowRender">
72+
<GridColumns>
73+
<GridColumn Field="@(nameof(SampleData.Id))" Width="100px" />
74+
<GridColumn Field="@(nameof(SampleData.Name))" Title="Employee Name" Width="100px" />
75+
<GridColumn Field="@(nameof(SampleData.Team))" Title="Team" Width="100px" />
76+
<GridColumn Field="@(nameof(SampleData.Note))" Title="Notes" Width="200px" />
77+
<GridColumn Field="@(nameof(SampleData.HireDate))" Title="Hire Date" Width="100px" />
78+
<GridColumn Title="Empty Column" />
79+
</GridColumns>
80+
</TelerikGrid>
81+
6482
<style>
6583
/* template */
6684
div.custom-ellipsis,
6785
/* OnCellRender */
68-
.k-grid td.custom-ellipsis {
86+
.k-grid td.custom-ellipsis,
87+
/* OnRowRender */
88+
.k-grid tr.custom-ellipsis .k-table-td {
6989
overflow: hidden;
7090
text-overflow: ellipsis;
7191
white-space: nowrap;
@@ -87,27 +107,34 @@ Resize Note column or double click on a row to see the product details
87107
</TelerikWindow>
88108
89109
@code {
90-
bool WindowIsVisible { get; set; }
110+
private bool WindowIsVisible { get; set; }
91111
92-
SampleData CurrEmployee { get; set; } = new SampleData();
112+
private SampleData CurrEmployee { get; set; } = new SampleData();
93113
94-
void OnRowDoubleClickHandler(GridRowClickEventArgs args)
114+
private void OnRowDoubleClickHandler(GridRowClickEventArgs args)
95115
{
96116
CurrEmployee = args.Item as SampleData;
97117
98118
WindowIsVisible = !WindowIsVisible;
99119
}
100120
101-
void OnCellRenderHandler(GridCellRenderEventArgs args)
121+
// apply ellipsis to specific columns
122+
private void OnCellRenderHandler(GridCellRenderEventArgs args)
123+
{
124+
args.Class = "custom-ellipsis";
125+
}
126+
127+
// apply ellipsis to all columns
128+
private void OnRowRender(GridRowRenderEventArgs args)
102129
{
103130
args.Class = "custom-ellipsis";
104131
}
105132
106133
public IEnumerable<SampleData> MyData = Enumerable.Range(1, 30).Select(x => new SampleData
107134
{
108135
Id = x,
109-
Name = "Employee " + x,
110-
Team = "team " + x % 5,
136+
Name = "Employee Name " + x,
137+
Team = "Team Name " + x % 5,
111138
Note = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has... ",
112139
HireDate = DateTime.Now.AddDays(-x).Date
113140
});
@@ -126,5 +153,3 @@ Resize Note column or double click on a row to see the product details
126153
## See also
127154

128155
* [Knowledge-Base article: Long text in TreeList does not align with the corresponding level]({%slug treelist-longer-text-starts-from-root-level%})
129-
130-

0 commit comments

Comments
 (0)