Skip to content

Commit 2f4cb43

Browse files
ntachevadimodi
andauthored
[3.6] docs(gantt,treelist): Documentation for Rebind method (#1129)
* docs(gantt,treelist):rebind docs * docs(carousel, treeview):rebind docs * docs(panelbar):rwbind docs * docs(common):minor fixes * Update components/gantt/refresh-data.md Co-authored-by: Dimo Dimov <961014+dimodi@users.noreply.github.com> * docs(common):address feedback Co-authored-by: Dimo Dimov <961014+dimodi@users.noreply.github.com>
1 parent 96cf307 commit 2f4cb43

File tree

10 files changed

+1314
-94
lines changed

10 files changed

+1314
-94
lines changed

_contentTemplates/common/observable-data.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ Databound components can benefit from live data - when the data source collectio
1010
When the `Data` of the component is a collection that implements the `INotifyCollectionChanged` interface (such as `ObservableCollection`), the Telerik components subscribe to its `CollectionChanged` event to update. This means that adding items, removing items, or clearing the collection updates the components (its `.Add()`, `.Remove()` and `.Clear()` methods).
1111

1212
The Observable collections fire the `CollectionChanged` event only when their `Add`, `Remove` and `Clear` methods are called. They do not fire it when you change the value of a field of one of their elements.
13+
#end
1314

15+
#observable-data-onread-note
1416
>important Observable data is not supported with manual data operations via the `OnRead` event.
1517
#end
1618

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#intro
2+
You can refresh the data by invoking the [`Rebind` method]({%slug common-features-data-binding-overview%}#refresh-data). Use the component reference to call the `Rebind` method after you have made the data changes (for example adding, removing items). This is needed in case you are not using [Observable data](#observable-data) or [resetting the collection reference](#new-collection-reference). Calling `Rebind` will force the component process the available data anew to reflect the updates.
3+
4+
>caption Use the `Rebind` method to refresh the data.
5+
#end

components/carousel/refresh-data.md

Lines changed: 117 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Refresh Data
33
page_title: Carousel Refresh Data
4-
description: Refresh Carousel Data using Observable Data or creating a new Collection reference.
4+
description: Refresh Carousel Data using the Rebind method, Observable Data or creating a new Collection reference.
55
slug: carousel-refresh-data
66
tags: telerik,blazor,carousel,observable,data,new,collection
77
published: True
@@ -13,32 +13,42 @@ position: 15
1313
@[template](/_contentTemplates/common/observable-data.md#intro)
1414

1515
In this article:
16+
- [Rebind Method](#rebind-method)
1617
- [Observable Data](#observable-data)
1718
- [New Collection Reference](#new-collection-reference)
1819

19-
## Observable Data
20-
21-
@[template](/_contentTemplates/common/observable-data.md#observable-data)
20+
## Rebind Method
2221

23-
>caption Bind the Carousel component to an ObservableCollection, so it can react to collection changes.
22+
@[template](/_contentTemplates/common/rebind-method.md#intro)
2423

2524
````CSHTML
26-
@* Add/remove an item to see how the Carousel reacts to that change. *@
27-
28-
@using System.Collections.ObjectModel
25+
@* Add/remove an item and rebind the Carousel to react to that change. *@
2926
3027
<TelerikButton OnClick="@AddItem">Add item</TelerikButton>
3128
3229
<TelerikButton OnClick="@RemoveItem">Remove item</TelerikButton>
3330
34-
<TelerikCarousel Data="@CarouselData"
31+
<TelerikCarousel @ref="@CarouselRef"
32+
Data="@CarouselData"
3533
Width="400px" Height="200px">
3634
<Template>
3735
<div class="item">ID @(context.ID) : @(context.Text)</div>
3836
</Template>
3937
</TelerikCarousel>
4038
39+
<style>
40+
.item {
41+
background: #3d57d8;
42+
color: #fff;
43+
font: 36px/200px sans-serif;
44+
text-align: center;
45+
}
46+
</style>
47+
4148
@code {
49+
private TelerikCarousel<CarouselModel> CarouselRef;
50+
51+
private List<CarouselModel> CarouselData = new List<CarouselModel>();
4252
4353
void AddItem()
4454
{
@@ -47,27 +57,58 @@ In this article:
4757
{
4858
ID = 4,
4959
Text = "Text 4"
50-
});
60+
});
61+
62+
CarouselRef.Rebind();
5163
}
5264
5365
void RemoveItem()
5466
{
5567
CarouselData.RemoveAt(CarouselData.Count() - 1);
68+
69+
CarouselRef.Rebind();
5670
}
5771
58-
public ObservableCollection<CarouselModel> CarouselData = new ObservableCollection<CarouselModel>
72+
protected override void OnInitialized()
5973
{
60-
new CarouselModel { ID = 1, Text = "Text 1" },
61-
new CarouselModel { ID = 2, Text = "Text 2" },
62-
new CarouselModel { ID = 3, Text = "Text 3" }
63-
};
74+
CarouselData = new List<CarouselModel>
75+
{
76+
new CarouselModel { ID = 1, Text = "Text 1" },
77+
new CarouselModel { ID = 2, Text = "Text 2" },
78+
new CarouselModel { ID = 3, Text = "Text 3" }
79+
};
80+
}
6481
6582
public class CarouselModel
6683
{
6784
public int ID { get; set; }
6885
public string Text { get; set; }
6986
}
7087
}
88+
````
89+
90+
91+
## Observable Data
92+
93+
@[template](/_contentTemplates/common/observable-data.md#observable-data)
94+
95+
>caption Bind the Carousel component to an ObservableCollection, so it can react to collection changes.
96+
97+
````CSHTML
98+
@* Add/remove an item to see how the Carousel reacts to that change. *@
99+
100+
@using System.Collections.ObjectModel
101+
102+
<TelerikButton OnClick="@AddItem">Add item</TelerikButton>
103+
104+
<TelerikButton OnClick="@RemoveItem">Remove item</TelerikButton>
105+
106+
<TelerikCarousel Data="@CarouselData"
107+
Width="400px" Height="200px">
108+
<Template>
109+
<div class="item">ID @(context.ID) : @(context.Text)</div>
110+
</Template>
111+
</TelerikCarousel>
71112
72113
<style>
73114
.item {
@@ -78,6 +119,40 @@ In this article:
78119
}
79120
</style>
80121
122+
@code {
123+
private ObservableCollection<CarouselModel> CarouselData = new ObservableCollection<CarouselModel>();
124+
125+
void AddItem()
126+
{
127+
CarouselData.Add(
128+
new CarouselModel()
129+
{
130+
ID = 4,
131+
Text = "Text 4"
132+
});
133+
}
134+
135+
void RemoveItem()
136+
{
137+
CarouselData.RemoveAt(CarouselData.Count() - 1);
138+
}
139+
140+
protected override void OnInitialized()
141+
{
142+
CarouselData = new ObservableCollection<CarouselModel>
143+
{
144+
new CarouselModel { ID = 1, Text = "Text 1" },
145+
new CarouselModel { ID = 2, Text = "Text 2" },
146+
new CarouselModel { ID = 3, Text = "Text 3" }
147+
};
148+
}
149+
150+
public class CarouselModel
151+
{
152+
public int ID { get; set; }
153+
public string Text { get; set; }
154+
}
155+
}
81156
````
82157
## New Collection Reference
83158

@@ -101,9 +176,19 @@ In this article:
101176
</Template>
102177
</TelerikCarousel>
103178
179+
<style>
180+
.item {
181+
background: #3d57d8;
182+
color: #fff;
183+
font: 36px/200px sans-serif;
184+
text-align: center;
185+
}
186+
</style>
187+
104188
@code {
189+
private List<CarouselModel> CarouselData = new List<CarouselModel>();
105190
106-
void AddItem()
191+
private void AddItem()
107192
{
108193
CarouselData.Add(
109194
new CarouselModel()
@@ -115,45 +200,39 @@ In this article:
115200
CarouselData = new List<CarouselModel>(CarouselData);
116201
}
117202
118-
void RemoveItem()
203+
private void RemoveItem()
119204
{
120205
CarouselData.RemoveAt(CarouselData.Count() - 1);
121206
122207
CarouselData = new List<CarouselModel>(CarouselData);
123208
}
124209
125-
void LoadNew()
210+
private void LoadNew()
126211
{
127212
CarouselData = new List<CarouselModel>
128-
{
129-
new CarouselModel { ID = 4, Text = "New Item 4" },
130-
new CarouselModel { ID = 5, Text = "New Item 5" },
131-
new CarouselModel { ID = 6, Text = "New Item 6" }
132-
};
213+
{
214+
new CarouselModel { ID = 4, Text = "New Item 4" },
215+
new CarouselModel { ID = 5, Text = "New Item 5" },
216+
new CarouselModel { ID = 6, Text = "New Item 6" }
217+
};
133218
}
134219
135-
public List<CarouselModel> CarouselData = new List<CarouselModel>
136-
{
137-
new CarouselModel { ID = 1, Text = "Text 1" },
138-
new CarouselModel { ID = 2, Text = "Text 2" },
139-
new CarouselModel { ID = 3, Text = "Text 3" }
140-
};
220+
protected override void OnInitialized()
221+
{
222+
CarouselData = new List<CarouselModel>
223+
{
224+
new CarouselModel { ID = 1, Text = "Text 1" },
225+
new CarouselModel { ID = 2, Text = "Text 2" },
226+
new CarouselModel { ID = 3, Text = "Text 3" }
227+
};
228+
}
141229
142230
public class CarouselModel
143231
{
144232
public int ID { get; set; }
145233
public string Text { get; set; }
146234
}
147235
}
148-
149-
<style>
150-
.item {
151-
background: #3d57d8;
152-
color: #fff;
153-
font: 36px/200px sans-serif;
154-
text-align: center;
155-
}
156-
</style>
157236
````
158237

159238
## See Also

components/gantt/events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Events of the Gantt for Blazor
55
slug: gantt-events
66
tags: telerik,blazor,gantt,events
77
published: True
8-
position: 20
8+
position: 25
99
---
1010

1111
# Gantt Events

0 commit comments

Comments
 (0)