Skip to content

Commit 7c0fa08

Browse files
chore(listview): fix refresh article (#1185)
* chore(listview): fix refresh article * chore(listview): fixes as per comment
1 parent bdc78cd commit 7c0fa08

File tree

1 file changed

+52
-44
lines changed

1 file changed

+52
-44
lines changed

components/listview/refresh-data.md

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,75 +20,83 @@ In this article:
2020

2121
## Rebind Method
2222

23-
To refresh the ComboBox data when using [`OnRead`]({%slug autocomplete-events%}#onread), call the `Rebind` method of the TelerikAutoComplete reference. This will fire the `OnRead` event and execute the business logic in the handler.
23+
To refresh the `ListView` data when using [`OnRead`]({%slug listview-manual-operations%}), call the `Rebind` method of the `TelerikListView` reference. This will fire the `OnRead` event and execute the business logic in the handler.
2424

2525
````CSHTML
2626
@* Clicking on the Rebind button will delete the first item from the ListView and refresh the data *@
2727
2828
@using Telerik.DataSource.Extensions
2929
3030
<div class="example-box">
31-
<h3>Pressing rebind will remove the first item from the combobox and rebind it.</h3>
32-
<TelerikButton OnClick="@RebindComboBox">Rebind</TelerikButton>
33-
<TelerikComboBox @ref="@ComboBoxRef"
34-
TItem="Product" TValue="int"
31+
<h3>Pressing rebind will remove the first item from the listview and rebind it.</h3>
32+
<TelerikButton OnClick="@RebindListView">Rebind</TelerikButton>
33+
<TelerikListView @ref="@ListViewRef"
34+
TItem="SampleData"
3535
OnRead="@ReadItems"
36-
ValueField="@nameof(Product.ProductId)"
37-
TextField="@nameof(Product.ProductName)"
38-
Filterable="true"
39-
Placeholder="Find what you seek by typing"
40-
@bind-Value="@SelectedValue">
41-
</TelerikComboBox>
36+
Width="500px"
37+
Height="700px">
38+
<Template>
39+
<div class="listview-item">
40+
<h4>@context.Name</h4>
41+
<h5>@context.Team</h5>
42+
</div>
43+
</Template>
44+
</TelerikListView>
4245
</div>
4346
44-
@code{
45-
public int SelectedValue { get; set; }
46-
List<Product> AllData { get; set; } = new List<Product>();
47-
public TelerikComboBox<Product, int> ComboBoxRef { get; set; }
47+
@code {
48+
private List<SampleData> SourceData { get; set; }
49+
private TelerikListView<SampleData> ListViewRef { get; set; }
4850
49-
async Task ReadItems(ComboBoxReadEventArgs args)
51+
void ReadItems(ListViewReadEventArgs args)
5052
{
51-
await Task.Delay(1000);
52-
args.Data = AllData.ToDataSourceResult(args.Request).Data;
53+
if (SourceData == null)
54+
{
55+
SourceData = Enumerable.Range(1, 5).Select(x => new SampleData
56+
{
57+
Id = x,
58+
Name = $"Name {x}",
59+
Team = $"Team {x}"
60+
}).ToList();
61+
}
62+
63+
var datasourceResult = SourceData.ToDataSourceResult(args.Request);
64+
65+
args.Data = datasourceResult.Data;
66+
args.Total = datasourceResult.Total;
5367
}
5468
55-
protected override void OnInitialized()
69+
void RebindListView()
5670
{
57-
List<Product> products = new List<Product>();
58-
for (int i = 0; i < 200; i++)
71+
if (SourceData.Count > 0)
5972
{
60-
products.Add(new Product()
61-
{
62-
ProductId = i,
63-
ProductName = "Product" + i.ToString(),
64-
SupplierId = i,
65-
UnitPrice = (decimal)(i * 3.14),
66-
UnitsInStock = (short)(i * 1),
67-
});
73+
SourceData.RemoveAt(0);
6874
}
6975
70-
AllData = products;
76+
ListViewRef.Rebind();
7177
}
7278
73-
public class Product
79+
public class SampleData
7480
{
75-
public int ProductId { get; set; }
76-
public string ProductName { get; set; }
77-
public int SupplierId { get; set; }
78-
public decimal UnitPrice { get; set; }
79-
public short UnitsInStock { get; set; }
81+
public int Id { get; set; }
82+
public string Name { get; set; }
83+
public string Team { get; set; }
8084
}
85+
}
8186
82-
private void RebindComboBox()
83-
{
84-
if (AllData.Count > 0)
85-
{
86-
AllData.RemoveAt(0);
87-
}
87+
@* Styles would usually go to to the site stylesheet *@
8888
89-
ComboBoxRef.Rebind();
89+
<style>
90+
.listview-item {
91+
height: 150px;
92+
width: 150px;
93+
display: inline-block;
94+
margin: 10px;
95+
border: 1px solid black;
96+
border-radius: 10px;
97+
padding: 10px;
9098
}
91-
}
99+
</style>
92100
````
93101

94102
@[template](/_contentTemplates/common/refresh-data-not-applicable.md#refresh-data-note)

0 commit comments

Comments
 (0)