Skip to content

Commit 1301dfe

Browse files
svdimitrdimodi
andauthored
[3.6.0] OnItemRender event documentation (#1137)
* docs(autocomplete): OnItemRender docs * docs(dropdownlist): OnItemRender event docs * docs(multiselect): OnItemRender event docs * docs(combobox): OnItemRender event docs * Update components/autocomplete/events.md Co-authored-by: Dimo Dimov <961014+dimodi@users.noreply.github.com> * docs(selects): implement the suggested improvements Co-authored-by: Dimo Dimov <961014+dimodi@users.noreply.github.com>
1 parent f200de9 commit 1301dfe

File tree

4 files changed

+225
-1
lines changed

4 files changed

+225
-1
lines changed

components/autocomplete/events.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This article explains the events available in the Telerik AutoComplete for Blazo
1515
* [ValueChanged](#valuechanged)
1616
* [OnChange](#onchange)
1717
* [OnRead](#onread)
18+
* [OnItemRender](#onitemrender)
1819
* [OnBlur](#onblur)
1920

2021
## ValueChanged
@@ -227,6 +228,63 @@ When using `OnRead`, make sure to set `TItem` and `TValue`.
227228
}
228229
````
229230

231+
## OnItemRender
232+
233+
The `OnItemRender` event fires when each item in the AutoComplete dropdown renders.
234+
235+
The event handler receives as an argument an `AutoCompleteItemRenderEventArgs<TItem>` object that contains:
236+
237+
@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout)
238+
239+
| Property | Description |
240+
| --- | --- |
241+
| `Item` | The current item that renders in the AutoComplete. |
242+
| `Class` | The custom CSS class that will be added to the item. |
243+
244+
````CSHTML
245+
@* Customize an item in the AutoComplete *@
246+
247+
<style>
248+
.customized-item{
249+
font-weight:bold;
250+
color: white;
251+
background-color: blue;
252+
}
253+
</style>
254+
255+
<TelerikAutoComplete Data="@Suggestions"
256+
OnItemRender="@OnItemRenderHandler"
257+
ValueField="@(nameof(SuggestionsModel.Suggestion))"
258+
@bind-Value="@AutoCompleteValue" />
259+
260+
@code {
261+
private string AutoCompleteValue { get; set; }
262+
263+
private void OnItemRenderHandler(AutoCompleteItemRenderEventArgs<SuggestionsModel> args)
264+
{
265+
SuggestionsModel currentItem = args.Item;
266+
267+
if (currentItem.Suggestion == "second" && currentItem.UniqueIdentifier == 2)
268+
{
269+
args.Class = "customized-item";
270+
}
271+
}
272+
273+
List<SuggestionsModel> Suggestions { get; set; } = new List<SuggestionsModel>
274+
{
275+
new SuggestionsModel { Suggestion = "first", UniqueIdentifier = 1 },
276+
new SuggestionsModel { Suggestion = "second", UniqueIdentifier = 2 },
277+
new SuggestionsModel { Suggestion = "third", UniqueIdentifier = 3 }
278+
};
279+
280+
public class SuggestionsModel
281+
{
282+
public string Suggestion { get; set; }
283+
public int UniqueIdentifier { get; set; }
284+
}
285+
}
286+
````
287+
230288
## OnBlur
231289

232290
The `OnBlur` event fires when the component loses focus.
@@ -251,7 +309,6 @@ The `OnBlur` event fires when the component loses focus.
251309
}
252310
````
253311

254-
255312
## See Also
256313

257314
* [ValueChanged and Validation]({%slug value-changed-validation-model%})

components/combobox/events.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This article explains the events available in the Telerik ComboBox for Blazor:
1515
* [ValueChanged](#valuechanged)
1616
* [OnChange](#onchange)
1717
* [OnRead](#onread)
18+
* [OnItemRender](#onitemrender)
1819
* [OnBlur](#onblur)
1920

2021
## ValueChanged
@@ -300,6 +301,59 @@ When using `OnRead`, make sure to set `TItem` and `TValue`.
300301
}
301302
````
302303

304+
## OnItemRender
305+
306+
The `OnItemRender` event fires when each item in the ComboBox dropdown renders.
307+
308+
The event handler receives as an argument an `ComboBoxItemRenderEventArgs<TItem>` object that contains:
309+
310+
@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout)
311+
312+
| Property | Description |
313+
| --- | --- |
314+
| `Item` | The current item that renders in the ComboBox. |
315+
| `Class` | The custom CSS class that will be added to the item. |
316+
317+
````CSHTML
318+
@* Customize an item in the ComboBox *@
319+
320+
<style>
321+
.customized-item {
322+
font-weight:bold;
323+
color: white;
324+
background-color: blue;
325+
}
326+
</style>
327+
328+
<TelerikComboBox Data="@ComboBoxData"
329+
OnItemRender="@OnItemRenderHandler"
330+
TextField="ItemText"
331+
ValueField="ItemId"
332+
@bind-Value="ComboBoxValue">
333+
</TelerikComboBox>
334+
335+
@code {
336+
private int ComboBoxValue { get; set; }
337+
338+
public void OnItemRenderHandler(ComboBoxItemRenderEventArgs<ItemDescriptor> args)
339+
{
340+
ItemDescriptor currentItem = args.Item;
341+
342+
if (currentItem.ItemText == "item 2" && currentItem.ItemId == 2)
343+
{
344+
args.Class = "customized-item";
345+
}
346+
}
347+
348+
private IEnumerable<ItemDescriptor> ComboBoxData = Enumerable.Range(1, 20).Select(x => new ItemDescriptor { ItemText = "item " + x, ItemId = x });
349+
350+
public class ItemDescriptor
351+
{
352+
public int ItemId { get; set; }
353+
public string ItemText { get; set; }
354+
}
355+
}
356+
````
303357

304358
## OnBlur
305359

components/dropdownlist/events.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This article explains the events available in the Telerik DropDownList for Blazo
1515
* [OnChange](#onchange)
1616
* [ValueChanged](#valuechanged)
1717
* [OnRead](#onread)
18+
* [OnItemRender](#onitemrender)
1819
* [OnBlur](#onblur)
1920

2021
The examples in this article use `string` values and simple data sources for brevity. You can use full models, see the [data binding]({%slug components/dropdownlist/databind%}) article for more details.
@@ -225,6 +226,59 @@ You can also call remote data through `async` operations.
225226
}
226227
````
227228

229+
## OnItemRender
230+
231+
The `OnItemRender` event fires when each item in the DropDownList popup renders.
232+
233+
The event handler receives as an argument an `DropDownListItemRenderEventArgs<TItem>` object that contains:
234+
235+
@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout)
236+
237+
| Property | Description |
238+
| --- | --- |
239+
| `Item` | The current item that renders in the DropDownList. |
240+
| `Class` | The custom CSS class that will be added to the item. |
241+
242+
````CSHTML
243+
@* Customize an item in the DropDownList *@
244+
245+
<style>
246+
.customized-item {
247+
font-weight:bold;
248+
color: white;
249+
background-color: blue;
250+
}
251+
</style>
252+
253+
<TelerikDropDownList Data="@DropDownListData"
254+
OnItemRender="@OnItemRenderHandler"
255+
TextField="ItemText"
256+
ValueField="ItemId"
257+
@bind-Value="DropDownListValue">
258+
</TelerikDropDownList>
259+
260+
@code {
261+
private int DropDownListValue { get; set; }
262+
263+
private void OnItemRenderHandler(DropDownListItemRenderEventArgs<ItemDescriptor> args)
264+
{
265+
ItemDescriptor currentItem = args.Item;
266+
267+
if (currentItem.ItemText == "item 4" && currentItem.ItemId == 4)
268+
{
269+
args.Class = "customized-item";
270+
}
271+
}
272+
273+
private IEnumerable<ItemDescriptor> DropDownListData = Enumerable.Range(1, 20).Select(x => new ItemDescriptor { ItemText = "item " + x, ItemId = x });
274+
275+
public class ItemDescriptor
276+
{
277+
public int ItemId { get; set; }
278+
public string ItemText { get; set; }
279+
}
280+
}
281+
````
228282

229283
## OnBlur
230284

components/multiselect/events.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This article explains the events available in the Telerik MultiSelect for Blazor
1414

1515
* [ValueChanged](#valuechanged)
1616
* [OnChange](#onchange)
17+
* [OnItemRender](#OnItemRender)
1718
* [OnRead](#onread)
1819
* [OnBlur](#onblur)
1920

@@ -218,6 +219,64 @@ You can also call remote data through async operations.
218219
}
219220
````
220221

222+
## OnItemRender
223+
224+
The `OnItemRender` event fires when each item in the MultiSelect dropdown renders.
225+
226+
The event handler receives as an argument an `MultiSelectItemRenderEventArgs<TItem>` object that contains:
227+
228+
@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout)
229+
230+
| Property | Description |
231+
| --- | --- |
232+
| `Item` | The current item that renders in the MultiSelect. |
233+
| `Class` | The custom CSS class that will be added to the item. |
234+
235+
````CSHTML
236+
@* Customize an item in the MultiSelect *@
237+
238+
<style>
239+
.customized-item {
240+
font-weight:bold;
241+
color: white;
242+
background-color: blue;
243+
}
244+
</style>
245+
246+
<TelerikMultiSelect Data="@Options"
247+
OnItemRender="@OnItemRenderHandler"
248+
@bind-Value="@MultiSelectValues"
249+
TextField="StringRepresentation"
250+
ValueField="UniqueIdentifier" />
251+
252+
@code {
253+
private List<int> MultiSelectValues { get; set; }
254+
255+
private void OnItemRenderHandler(MultiSelectItemRenderEventArgs<OptionsModel> args)
256+
{
257+
OptionsModel currentItem = args.Item;
258+
259+
if (currentItem.StringRepresentation == "third" && currentItem.UniqueIdentifier == 3)
260+
{
261+
args.Class = "customized-item";
262+
}
263+
}
264+
265+
private List<OptionsModel> Options { get; set; } = new List<OptionsModel>
266+
{
267+
new OptionsModel { StringRepresentation = "first", UniqueIdentifier = 1 },
268+
new OptionsModel { StringRepresentation = "second", UniqueIdentifier = 2 },
269+
new OptionsModel { StringRepresentation = "third", UniqueIdentifier = 3 }
270+
};
271+
272+
public class OptionsModel
273+
{
274+
public string StringRepresentation { get; set; }
275+
public int UniqueIdentifier { get; set; }
276+
}
277+
}
278+
````
279+
221280
## OnBlur
222281

223282
The `OnBlur` event fires when the component loses focus.

0 commit comments

Comments
 (0)