You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// check if the item is expanding, we don't need to do anything if it is collapsing
82
-
// in this example we will also check the type of the model to know how to identify the node and what data to load. If you use only one model for all levels, you don't have to do this
83
-
if (args.Expanded && args.Item is ProductCategoryItem)
84
-
{
85
-
ProductCategoryItem currCategory = args.Item as ProductCategoryItem;
86
-
if (currCategory.Products?.Count > 0)
87
-
{
88
-
return; // item has been expanded before so it has data, don't load data again
89
-
// alternatively, load it again but make sure to handle the child items correctly
90
-
// either overwrite the entire collection, or use some other logic to append/merge
91
-
}
92
-
int itemIdentifier = currCategory.CategoryId;
93
-
// in a similar fashion, you can identify the item that was just expanded through its properties
94
-
// in this example, we will hardcode some data and logic for brevity
95
-
// in a real case, you would probably await a remote endpoint/service
96
-
97
-
if (itemIdentifier == 2) // simulate no data for a certain node - the second in our example
98
-
{
99
-
currCategory.HasChildren = false; // remove the expand icon from the node
100
-
101
-
StateHasChanged(); // inform the UI that the data is changed
102
-
103
-
return;
104
-
}
35
+
public List<ProductCategoryItem> HierarchicalData { get; set; }
36
+
37
+
public class ProductCategoryItem
38
+
{
39
+
public string Category { get; set; }
40
+
public int CategoryId { get; set; } //will be used to identify the node, not for rendering in this example
41
+
public List<ProductItem> Products { get; set; }
42
+
public bool Expanded { get; set; }
43
+
public bool HasChildren { get; set; }
44
+
}
45
+
46
+
public class ProductItem
47
+
{
48
+
public string ProductName { get; set; }
49
+
// the following fields are to denote you can keep having hierarchy further down. They are not required
50
+
// they are not really used in this example and you would have a collection of child items too
51
+
// see the information about multiple data bindings earlier in this article on using them
52
+
public bool Expanded { get; set; }
53
+
public bool HasChildren { get; set; }
54
+
}
55
+
56
+
protected override void OnInitialized()
57
+
{
58
+
LoadRootHierarchical();
59
+
}
60
+
61
+
private void LoadRootHierarchical()
62
+
{
63
+
HierarchicalData = new List<ProductCategoryItem>();
64
+
65
+
HierarchicalData.Add(new ProductCategoryItem
66
+
{
67
+
Category = "Category 1",
68
+
HasChildren = true, // allow the user to expand the item and load children on demand
69
+
CategoryId = 1 // an identifier for use in the service call for child items
// check if the item is expanding, we don't need to do anything if it is collapsing
83
+
// in this example we will also check the type of the model to know how to identify the node and what data to load. If you use only one model for all levels, you don't have to do this
84
+
if (args.Expanded && args.Item is ProductCategoryItem)
85
+
{
86
+
ProductCategoryItem currCategory = args.Item as ProductCategoryItem;
87
+
if (currCategory.Products?.Count > 0)
88
+
{
89
+
return; // item has been expanded before so it has data, don't load data again
90
+
// alternatively, load it again but make sure to handle the child items correctly
91
+
// either overwrite the entire collection, or use some other logic to append/merge
92
+
}
93
+
int itemIdentifier = currCategory.CategoryId;
94
+
// in a similar fashion, you can identify the item that was just expanded through its properties
95
+
// in this example, we will hardcode some data and logic for brevity
96
+
// in a real case, you would probably await a remote endpoint/service
97
+
98
+
if (itemIdentifier == 2) // simulate no data for a certain node - the second in our example
99
+
{
100
+
currCategory.HasChildren = false; // remove the expand icon from the node
101
+
102
+
StateHasChanged(); // inform the UI that the data is changed
103
+
104
+
return;
105
+
}
105
106
106
107
// data requested and received for a certain node
107
-
List<ProductItem> theProducts = new List<ProductItem>() {
108
-
new ProductItem { ProductName= $"Category {itemIdentifier} - Product 1" },
109
-
new ProductItem { ProductName= $"Category {itemIdentifier} - Product 2" }
Copy file name to clipboardExpand all lines: knowledge-base/grid-force-refresh.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -68,7 +68,7 @@ When using manual operations through the [OnRead event](https://docs.telerik.com
68
68
public ObservableCollection<Employee> GridData { get; set; } = new ObservableCollection<Employee>(); //prevent null reference errors by intializing the field
69
69
DataSourceRequest LastRequest { get; set; }//store the last request so we can repeat it when changing the data
0 commit comments