From a0d8560d290c9fc453987a0f77e778f37579ca92 Mon Sep 17 00:00:00 2001 From: Hristian Stefanov Date: Tue, 25 Oct 2022 14:58:02 +0300 Subject: [PATCH 1/2] chore(listview): fix refresh article --- components/listview/refresh-data.md | 96 ++++++++++++++++------------- 1 file changed, 52 insertions(+), 44 deletions(-) diff --git a/components/listview/refresh-data.md b/components/listview/refresh-data.md index 935ca94395..a6626636cd 100644 --- a/components/listview/refresh-data.md +++ b/components/listview/refresh-data.md @@ -20,7 +20,7 @@ In this article: ## Rebind Method -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. +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. ````CSHTML @* Clicking on the Rebind button will delete the first item from the ListView and refresh the data *@ @@ -28,67 +28,75 @@ To refresh the ComboBox data when using [`OnRead`]({%slug autocomplete-events%}# @using Telerik.DataSource.Extensions
-

Pressing rebind will remove the first item from the combobox and rebind it.

- Rebind - Pressing rebind will remove the first item from the listview and rebind it. + Rebind + - + Width="500px" + Height="700px"> + +
-@code{ - public int SelectedValue { get; set; } - List AllData { get; set; } = new List(); - public TelerikComboBox ComboBoxRef { get; set; } +@code { + public List SourceData { get; set; } + public TelerikListView ListViewRef { get; set; } - async Task ReadItems(ComboBoxReadEventArgs args) + protected async Task ReadItems(ListViewReadEventArgs args) { - await Task.Delay(1000); - args.Data = AllData.ToDataSourceResult(args.Request).Data; + if (SourceData == null) + { + SourceData = Enumerable.Range(1, 5).Select(x => new SampleData + { + Id = x, + Name = $"Name {x}", + Team = $"Team {x}" + }).ToList(); + } + + var datasourceResult = SourceData.ToDataSourceResult(args.Request); + + args.Data = datasourceResult.Data; + args.Total = datasourceResult.Total; } - protected override void OnInitialized() + private void RebindListView() { - List products = new List(); - for (int i = 0; i < 200; i++) + if (SourceData.Count > 0) { - products.Add(new Product() - { - ProductId = i, - ProductName = "Product" + i.ToString(), - SupplierId = i, - UnitPrice = (decimal)(i * 3.14), - UnitsInStock = (short)(i * 1), - }); + SourceData.RemoveAt(0); } - AllData = products; + ListViewRef.Rebind(); } - public class Product + public class SampleData { - public int ProductId { get; set; } - public string ProductName { get; set; } - public int SupplierId { get; set; } - public decimal UnitPrice { get; set; } - public short UnitsInStock { get; set; } + public int Id { get; set; } + public string Name { get; set; } + public string Team { get; set; } } +} - private void RebindComboBox() - { - if (AllData.Count > 0) - { - AllData.RemoveAt(0); - } + @* Styles would usually go to to the site stylesheet *@ - ComboBoxRef.Rebind(); + ```` @[template](/_contentTemplates/common/refresh-data-not-applicable.md#refresh-data-note) From 038fb0f9876930adda6828b5f08806d36172b30e Mon Sep 17 00:00:00 2001 From: Hristian Stefanov Date: Tue, 25 Oct 2022 15:17:46 +0300 Subject: [PATCH 2/2] chore(listview): fixes as per comment --- components/listview/refresh-data.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/listview/refresh-data.md b/components/listview/refresh-data.md index a6626636cd..9169903c57 100644 --- a/components/listview/refresh-data.md +++ b/components/listview/refresh-data.md @@ -45,10 +45,10 @@ To refresh the `ListView` data when using [`OnRead`]({%slug listview-manual-oper @code { - public List SourceData { get; set; } - public TelerikListView ListViewRef { get; set; } + private List SourceData { get; set; } + private TelerikListView ListViewRef { get; set; } - protected async Task ReadItems(ListViewReadEventArgs args) + void ReadItems(ListViewReadEventArgs args) { if (SourceData == null) { @@ -66,7 +66,7 @@ To refresh the `ListView` data when using [`OnRead`]({%slug listview-manual-oper args.Total = datasourceResult.Total; } - private void RebindListView() + void RebindListView() { if (SourceData.Count > 0) {