Skip to content

Commit e961b4e

Browse files
chore(common): explain how data update work in Blazor
1 parent 8870496 commit e961b4e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

common-features/observable-data.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Databound components can benefit from live data - when the data source collectio
1414

1515
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).
1616

17-
The following components support observable data:
17+
The following components support observable data for their `Data` parameter:
1818

1919
* AutoComplete
2020

@@ -34,6 +34,26 @@ The following components support observable data:
3434

3535
The Scheduler, Menu, Drawer, ContextMenu will receive this feature in a future release.
3636

37+
## Refresh Data
38+
39+
The most common reason you would use an ObservableCollection is to make a component (like a grid, treeview, treelist, dropdown) change or react when you change that collection.
40+
41+
When you want to refresh the component data source like that, there are two important framework behaviors you need to be aware of:
42+
43+
* Observable collections fire the `CollectionChanged` event (which the Telerik components subscribe to) only when their `Add`, `Remove` and `Clear` methods are called.
44+
45+
They do not fire it when you change the value of a field of one of their elements.
46+
47+
* In Blazor, the framework will fire the `OnParametersSet` event of a child component (which is how child components can react to outside changes) only when it can detect a change in the object it receives through the corresponding parameter (like `Data` for the data sources of Telerik components). This detection works as follows:
48+
49+
* For primitive types (such as numbers, strings), this happens when their value changes.
50+
51+
* For complex types (such as data collections like `List`, or any `IEnumerable`, and application-specific models/objects), this happens when the object reference changes.
52+
53+
Thus, you would usually need to create a `new` reference for the view-model field (such as `TreeViewData = new List<MyTreeViewItem>(theUpdatedDataCollection);`) when you want the component to update.
54+
55+
You can find some more explanations and examples for the Grid component in the [Force a Grid to Refresh]({%slug grid-force-refresh%}) Knowledge Base article.
56+
3757
## See Also
3858

3959
* [INotifyCollectionChanged Interface](https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.inotifycollectionchanged?view=netframework-4.8)

0 commit comments

Comments
 (0)