Skip to content

Commit 4414e9f

Browse files
authored
docs(common): Enhance common Rebind() example
1 parent a3b02d6 commit 4414e9f

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

common-features/data-binding/overview.md

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -115,31 +115,36 @@ Thus, you will usually need to create a new reference for `Data` value in order
115115
>caption Call `Rebind()` or create new Data reference
116116
117117
````RAZOR
118-
<p>
119-
<TelerikButton OnClick="@RefreshGridData">Refresh Grid Data</TelerikButton>
120-
</p>
121-
122118
<TelerikGrid @ref="@GridRef"
123119
Data="@GridData"
124-
AutoGenerateColumns="true" />
120+
AutoGenerateColumns="true">
121+
<GridToolBarTemplate>
122+
<TelerikButton ThemeColor="@ThemeConstants.Button.ThemeColor.Primary"
123+
OnClick="@RefreshGridData">Modify Grid Data And Refresh</TelerikButton>
124+
</GridToolBarTemplate>
125+
</TelerikGrid>
125126
126127
@code {
127-
TelerikGrid<SampleModel> GridRef { get; set; }
128-
List<SampleModel> GridData { get; set; }
128+
private TelerikGrid<SampleModel>? GridRef { get; set; }
129+
130+
private List<SampleModel> GridData { get; set; } = new();
131+
132+
private int LastId { get; set; }
129133
130-
void RefreshGridData()
134+
private void RefreshGridData()
131135
{
132-
var newId = GridData.Count + 1;
136+
GridData.RemoveAt(0);
133137
134-
GridData.FirstOrDefault().Text = DateTime.Now.Ticks.ToString();
138+
GridData.ElementAt(Random.Shared.Next(0, GridData.Count)).Text = DateTime.Now.Ticks.ToString();
135139
136-
GridData.Add(new SampleModel() {
137-
Id = newId,
138-
Text = "Text " + newId
140+
GridData.Add(new SampleModel()
141+
{
142+
Id = ++LastId,
143+
Text = "Text " + LastId
139144
});
140145
141146
// Call Rebind...
142-
GridRef.Rebind();
147+
GridRef?.Rebind();
143148
144149
// ...OR...
145150
@@ -152,13 +157,12 @@ Thus, you will usually need to create a new reference for `Data` value in order
152157
153158
protected override void OnInitialized()
154159
{
155-
GridData = new List<SampleModel>();
156-
157-
for (int i = 1; i <= 3; i++)
160+
for (int i = 1; i <= 5; i++)
158161
{
159-
GridData.Add(new SampleModel() {
160-
Id = i,
161-
Text = "Text " + i
162+
GridData.Add(new SampleModel()
163+
{
164+
Id = ++LastId,
165+
Text = $"Text {LastId}"
162166
});
163167
}
164168
@@ -168,7 +172,7 @@ Thus, you will usually need to create a new reference for `Data` value in order
168172
public class SampleModel
169173
{
170174
public int Id { get; set; }
171-
public string Text { get; set; }
175+
public string Text { get; set; } = string.Empty;
172176
}
173177
}
174178
````

0 commit comments

Comments
 (0)