diff --git a/src/BlazorWebFormsComponents.Test/GridView/AutogenerateColumns.razor b/src/BlazorWebFormsComponents.Test/GridView/AutogenerateColumns.razor index b8b5a1c..5c01985 100644 --- a/src/BlazorWebFormsComponents.Test/GridView/AutogenerateColumns.razor +++ b/src/BlazorWebFormsComponents.Test/GridView/AutogenerateColumns.razor @@ -10,27 +10,31 @@ @code { - void FirstTest() - { - var cut = GetComponentUnderTest(); - var tableHeaders = cut.FindAll("th").ToList(); - tableHeaders.Count.ShouldBe(4, "Did not render 4 TH elements"); - - try { - tableHeaders[0].TextContent.ShouldBe("Id"); - } catch (Exception ex) { - Console.WriteLine("HTML rendered: " + cut.Markup); - throw; - } + void FirstTest() + { + var cut = GetComponentUnderTest(); + System.Diagnostics.Debug.WriteLine(cut.Markup); + var tableHeaders = cut.FindAll("th").ToList(); + tableHeaders.Count.ShouldBe(4, "Did not render 4 TH elements"); - tableHeaders[1].TextContent.ShouldBe("Name"); - tableHeaders[2].TextContent.ShouldBe("Price"); - tableHeaders[3].TextContent.ShouldBe("LastUpdate"); + try + { + tableHeaders[0].TextContent.ShouldBe("Id"); } - - IQueryable GetWidgets(int maxRows, int startRowIndex, string sortByExpression, out int totalRowCount) + catch (Exception ex) { - totalRowCount = Widget.SimpleWidgetList.Length; - return Widget.SimpleWidgetList.AsQueryable(); + Console.WriteLine("HTML rendered: " + cut.Markup); + throw; } + + tableHeaders[1].TextContent.ShouldBe("Name"); + tableHeaders[2].TextContent.ShouldBe("Price"); + tableHeaders[3].TextContent.ShouldBe("LastUpdate"); + } + + IQueryable GetWidgets(int maxRows, int startRowIndex, string sortByExpression, out int totalRowCount) + { + totalRowCount = Widget.SimpleWidgetList.Length; + return Widget.SimpleWidgetList.AsQueryable(); + } } diff --git a/src/BlazorWebFormsComponents.Test/GridView/EmptyDataText.razor b/src/BlazorWebFormsComponents.Test/GridView/EmptyDataText.razor index 48e498f..40c566b 100644 --- a/src/BlazorWebFormsComponents.Test/GridView/EmptyDataText.razor +++ b/src/BlazorWebFormsComponents.Test/GridView/EmptyDataText.razor @@ -11,20 +11,20 @@ @code { - void FirstTest() - { - var cut = GetComponentUnderTest(); - var tableHeaders = cut.FindAll("th").ToList(); - tableHeaders.Count.ShouldBe(4, "Did not render 4 TH elements"); - cut.FindAll("tr").Count(e => e.InnerHtml.Contains("td")).ShouldBe(1, "Did not render 1 TR elements"); - cut.FindAll("td").Count().ShouldBe(1, "Did not render 0 TD elements"); - cut.Find("td").TextContent.Replace("\t", string.Empty).Replace("\n", string.Empty).ShouldBe("TestText"); - } + void FirstTest() + { + var cut = GetComponentUnderTest(); + var tableHeaders = cut.FindAll("th").ToList(); + tableHeaders.Count.ShouldBe(4, "Did not render 4 TH elements"); + cut.FindAll("tr").Count(e => e.InnerHtml.Contains("td")).ShouldBe(1, "Did not render 1 TR elements"); + cut.FindAll("td").Count().ShouldBe(1, "Did not render 0 TD elements"); + cut.Find("td").TextContent.Replace("\t", string.Empty).Replace("\n", string.Empty).ShouldBe("TestText"); + } - IQueryable GetWidgets(int maxRows, int startRowIndex, string sortByExpression, out int totalRowCount) - { - totalRowCount = 0; - var widgetList = new List(); - return widgetList.AsQueryable(); - } + IQueryable GetWidgets(int maxRows, int startRowIndex, string sortByExpression, out int totalRowCount) + { + totalRowCount = 0; + var widgetList = new List(); + return widgetList.AsQueryable(); + } } diff --git a/src/BlazorWebFormsComponents.Test/GridView/TemplateFields.razor b/src/BlazorWebFormsComponents.Test/GridView/TemplateFields.razor index 6760355..cfed59c 100644 --- a/src/BlazorWebFormsComponents.Test/GridView/TemplateFields.razor +++ b/src/BlazorWebFormsComponents.Test/GridView/TemplateFields.razor @@ -23,21 +23,24 @@ @code { - void FirstTest() - { - var cut = GetComponentUnderTest(); - var tableHeaders = cut.FindAll("th"); - tableHeaders[0].TextContent.ShouldBe("Name"); - tableHeaders[1].TextContent.ShouldBe("Price"); - tableHeaders.Count.ShouldBe(2, "Did not render 2 TH elements"); - cut.FindAll("tr").Count(e => e.InnerHtml.Contains("td")).ShouldBe(3, "Did not render 3 TR elements"); - cut.FindAll("td").Count(e => e.InnerHtml.Contains("label")).ShouldBe(3, "Did not render 3 labels"); - cut.FindAll("td").Count(e => e.InnerHtml.Contains("button")).ShouldBe(3, "Did not render 3 buttons"); - } + void FirstTest() + { + var cut = GetComponentUnderTest(); - IQueryable GetWidgets(int maxRows, int startRowIndex, string sortByExpression, out int totalRowCount) - { - totalRowCount = Widget.SimpleWidgetList.Length; - return Widget.SimpleWidgetList.AsQueryable(); - } + System.Diagnostics.Debug.WriteLine(cut.Markup); + var tableHeaders = cut.FindAll("th"); + tableHeaders[0].TextContent.ShouldBe("Name"); + tableHeaders[1].TextContent.ShouldBe("Price"); + tableHeaders.Count.ShouldBe(2, "Did not render 2 TH elements"); + cut.FindAll("tr").Count(e => e.InnerHtml.Contains("td")).ShouldBe(3, "Did not render 3 TR elements"); + cut.FindAll("td").Count(e => e.InnerHtml.Contains("label")).ShouldBe(3, "Did not render 3 labels"); + cut.FindAll("td").Count(e => e.InnerHtml.Contains("button")).ShouldBe(3, "Did not render 3 buttons"); + } + + IQueryable + GetWidgets(int maxRows, int startRowIndex, string sortByExpression, out int totalRowCount) + { + totalRowCount = Widget.SimpleWidgetList.Length; + return Widget.SimpleWidgetList.AsQueryable(); + } } diff --git a/src/BlazorWebFormsComponents/BaseColumn.cs b/src/BlazorWebFormsComponents/BaseColumn.cs index d6b06ba..ad4d3a2 100644 --- a/src/BlazorWebFormsComponents/BaseColumn.cs +++ b/src/BlazorWebFormsComponents/BaseColumn.cs @@ -3,24 +3,10 @@ namespace BlazorWebFormsComponents { - public abstract class BaseColumn : BaseWebFormsComponent, IColumn + public abstract class BaseColumn : BaseWebFormsComponent { - /// - [CascadingParameter(Name = "ColumnCollection")] - public IColumnCollection ParentColumnsCollection { get; set; } - - /// [Parameter] public string HeaderText { get; set; } - public void Dispose() - { - ParentColumnsCollection.RemoveColumn(this); - } - /// - protected override void OnInitialized() - { - ParentColumnsCollection.AddColumn(this); - } } } diff --git a/src/BlazorWebFormsComponents/BaseRow.cs b/src/BlazorWebFormsComponents/BaseRow.cs deleted file mode 100644 index 78846e9..0000000 --- a/src/BlazorWebFormsComponents/BaseRow.cs +++ /dev/null @@ -1,28 +0,0 @@ -using BlazorWebFormsComponents.Interfaces; -using Microsoft.AspNetCore.Components; - -namespace BlazorWebFormsComponents -{ - /// - /// Base abstract row class - /// - public abstract class BaseRow : BaseWebFormsComponent, IRow - { - /// - [CascadingParameter(Name = "RowCollection")] public IRowCollection RowCollection { get; set; } - - /// - [Parameter] public object DataItem { get; set; } - - public void Dispose() - { - RowCollection.RemoveRow(this); - } - - /// - protected override void OnInitialized() - { - RowCollection.AddRow(this); - } - } -} diff --git a/src/BlazorWebFormsComponents/GridView.razor b/src/BlazorWebFormsComponents/GridView.razor index 752fbf4..13791ec 100644 --- a/src/BlazorWebFormsComponents/GridView.razor +++ b/src/BlazorWebFormsComponents/GridView.razor @@ -1,39 +1,23 @@ -@typeparam ItemType -@inherits BaseModelBindingComponent -@using Interfaces -@if (ColumnList.Any()) -{ - +@inherits ListView +@typeparam ItemType + + + +
- - @foreach (IColumn column in ColumnList) - { - - } - - - - @if (Items != null && Items.Any()) + @foreach (var h in HeaderRow()) { - @foreach (ItemType item in Items) - { - - - - } - } - else - { - - - - } - -
@column.HeaderText
- @EmptyDataText -
-} - - - @Columns - + @h + } + + + @itemPlaceHolder + + + + + @code{ + } diff --git a/src/BlazorWebFormsComponents/GridView.razor.cs b/src/BlazorWebFormsComponents/GridView.razor.cs index bf3250e..c0f22d7 100644 --- a/src/BlazorWebFormsComponents/GridView.razor.cs +++ b/src/BlazorWebFormsComponents/GridView.razor.cs @@ -1,6 +1,6 @@ -using BlazorWebFormsComponents.Interfaces; -using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components; using System.Collections.Generic; +using System.Linq; namespace BlazorWebFormsComponents { @@ -8,14 +8,26 @@ namespace BlazorWebFormsComponents /// Blazor version of WebForms GridView control /// /// - public partial class GridView : BaseModelBindingComponent, IRowCollection, IColumnCollection - { + public partial class GridView : ListView + { /// /// Specify if the GridView component will autogenerate its columns /// [Parameter] public bool AutogenerateColumns { get; set; } = true; + [Parameter] public RenderFragment Columns { get; set; } + + public List BoundFields { get; set; } = new List(); + + public IEnumerable HeaderRow() + { + foreach (var x in BoundFields) + { + yield return x.HeaderText; + } + } + /// /// Text to show when there are no items to show /// @@ -32,26 +44,8 @@ public partial class GridView : BaseModelBindingComponent, I [Parameter] public string CssClass { get; set; } /// - public List ColumnList { get; set; } = new List(); - - /// - /// The Rows of the GridView - /// - public List Rows { get => RowList; set => RowList = value; } - - /// - public List RowList { get; set; } = new List(); #region Templates - /// - /// The columns template of the GridView - /// - [Parameter] public RenderFragment Columns { get; set; } - - /// - /// The ChildContent of the GridView - /// - [Parameter] public RenderFragment ChildContent { get; set; } #endregion protected override void OnInitialized() { @@ -61,34 +55,5 @@ protected override void OnInitialized() GridViewColumnGenerator.GenerateColumns(this); } } - - /// - public void AddColumn(IColumn column) - { - ColumnList.Add(column); - StateHasChanged(); - } - - /// - public void RemoveColumn(IColumn column) - { - ColumnList.Remove(column); - StateHasChanged(); - } - - /// - public void RemoveRow(IRow row) - { - Rows.Remove(row); - StateHasChanged(); - } - - /// - public void AddRow(IRow row) - { - Rows.Add(row); - StateHasChanged(); - } - } } diff --git a/src/BlazorWebFormsComponents/GridViewColumnGenerator.cs b/src/BlazorWebFormsComponents/GridViewColumnGenerator.cs index 810be5a..c64ae7d 100644 --- a/src/BlazorWebFormsComponents/GridViewColumnGenerator.cs +++ b/src/BlazorWebFormsComponents/GridViewColumnGenerator.cs @@ -6,8 +6,8 @@ namespace BlazorWebFormsComponents /// /// The GridView Column Generator /// - public static class GridViewColumnGenerator - { + public static class GridViewColumnGenerator + { /// /// Generate columns for a given GridView based on the properties of given Type /// @@ -19,12 +19,13 @@ public static void GenerateColumns(GridView gridView) var propertiesInfo = type.GetProperties(BindingFlags.Instance | BindingFlags.Public).OrderBy(x => x.MetadataToken); foreach (var propertyInfo in propertiesInfo) { - var newColumn = new BoundField { + var newColumn = new BoundField + { DataField = propertyInfo.Name, - ParentColumnsCollection = gridView, - HeaderText = propertyInfo.Name + HeaderText = propertyInfo.Name, }; - gridView.ColumnList.Add(newColumn); + gridView.BoundFields.Add(newColumn); + } } } diff --git a/src/BlazorWebFormsComponents/GridViewRow.razor b/src/BlazorWebFormsComponents/GridViewRow.razor deleted file mode 100644 index c7a2fa6..0000000 --- a/src/BlazorWebFormsComponents/GridViewRow.razor +++ /dev/null @@ -1,37 +0,0 @@ -@inherits BaseRow -@using Interfaces - - - @foreach (IColumn column in Columns) - { - - @if (column is BoundField) - { - var datafield = (BoundField)column; - var properties = datafield.DataField.Split('.'); - object obj = DataItem; - @foreach (var property in properties) - { - - var propertyInfo = obj.GetType().GetProperty(property); - obj = propertyInfo.GetValue(obj); - } - if (datafield.DataFormatString != null) - { - @String.Format(datafield.DataFormatString, @obj.ToString()) - } - else - { - @obj.ToString(); - } - } - else - { - var templateField = (TemplateField)column; - @templateField.ItemTemplate(DataItem) - - } - - } - - diff --git a/src/BlazorWebFormsComponents/GridViewRow.razor.cs b/src/BlazorWebFormsComponents/GridViewRow.razor.cs deleted file mode 100644 index a00aa3f..0000000 --- a/src/BlazorWebFormsComponents/GridViewRow.razor.cs +++ /dev/null @@ -1,29 +0,0 @@ -using BlazorWebFormsComponents.Interfaces; -using Microsoft.AspNetCore.Components; -using System.Collections.Generic; - -namespace BlazorWebFormsComponents -{ - /// - /// The row of a GridView - /// - public partial class GridViewRow: BaseRow - { - - /// - /// The data item Index - /// - [Parameter] public int DataItemIndex { get; set; } - - /// - /// The row index - /// - [Parameter] public int RowIndex { get; set; } - - /// - /// The columns of the Row - /// - [Parameter] public List Columns { get; set; } - - } -} diff --git a/src/BlazorWebFormsComponents/Interfaces/IColumn.cs b/src/BlazorWebFormsComponents/Interfaces/IColumn.cs deleted file mode 100644 index 23b25be..0000000 --- a/src/BlazorWebFormsComponents/Interfaces/IColumn.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace BlazorWebFormsComponents.Interfaces -{ - /// - /// Generic column interface - /// - public interface IColumn - { - /// - /// The header text of the column - /// - string HeaderText { get; set; } - - /// - /// The parent IColumnCollection where the IColumn resides - /// - IColumnCollection ParentColumnsCollection { get; set; } - } -} diff --git a/src/BlazorWebFormsComponents/Interfaces/IColumnCollection.cs b/src/BlazorWebFormsComponents/Interfaces/IColumnCollection.cs deleted file mode 100644 index 1283248..0000000 --- a/src/BlazorWebFormsComponents/Interfaces/IColumnCollection.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BlazorWebFormsComponents.Interfaces -{ - /// - /// Generic column collection interface - /// - public interface IColumnCollection - { - /// - /// The list of IColumns - /// - List ColumnList { get; set; } - - /// - /// Adds an IColumn to the collection - /// - /// - void AddColumn(IColumn column); - - /// - /// Removes an IColumn from the collection - /// - /// - void RemoveColumn(IColumn column); - } -} diff --git a/src/BlazorWebFormsComponents/Interfaces/IRow.cs b/src/BlazorWebFormsComponents/Interfaces/IRow.cs deleted file mode 100644 index 2bc0cd2..0000000 --- a/src/BlazorWebFormsComponents/Interfaces/IRow.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace BlazorWebFormsComponents.Interfaces -{ - /// - /// Generic row interface - /// - public interface IRow - { - /// - /// The parent IRowCollection where the IRow resides - /// - IRowCollection RowCollection { get; set; } - - /// - /// The object bound to the row - /// - object DataItem { get; set; } - } -} diff --git a/src/BlazorWebFormsComponents/Interfaces/IRowCollection.cs b/src/BlazorWebFormsComponents/Interfaces/IRowCollection.cs deleted file mode 100644 index 5f9281b..0000000 --- a/src/BlazorWebFormsComponents/Interfaces/IRowCollection.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BlazorWebFormsComponents.Interfaces -{ - /// - /// Generic collection of IRow - /// - public interface IRowCollection - { - /// - /// The list of IRows - /// - List RowList { get; set; } - - /// - /// Adds a IRow to the collection - /// - /// - void AddRow(IRow row); - - /// - /// Deletes an IRow from the collection - /// - /// - void RemoveRow(IRow row); - } -} diff --git a/src/BlazorWebFormsComponents/ListView.razor.cs b/src/BlazorWebFormsComponents/ListView.razor.cs index e7e72d5..616e5e6 100644 --- a/src/BlazorWebFormsComponents/ListView.razor.cs +++ b/src/BlazorWebFormsComponents/ListView.razor.cs @@ -23,7 +23,7 @@ public ListView() [Parameter] public RenderFragment GroupSeparatorTemplate { get; set; } [Parameter] public RenderFragment GroupTemplate { get; set; } [Parameter] public RenderFragment ItemPlaceHolder { get; set; } - /// + /// /// 🚨🚨 LayoutTemplate is not available. Please wrap the ListView component with the desired layout 🚨🚨 /// [Parameter] diff --git a/src/BlazorWebFormsComponents/TemplateField.razor.cs b/src/BlazorWebFormsComponents/TemplateField.razor.cs index 8790300..7481d6c 100644 --- a/src/BlazorWebFormsComponents/TemplateField.razor.cs +++ b/src/BlazorWebFormsComponents/TemplateField.razor.cs @@ -5,11 +5,11 @@ namespace BlazorWebFormsComponents /// /// A template field column /// - public partial class TemplateField: BaseColumn + public partial class TemplateField : BaseColumn { /// /// The item template /// - [Parameter] public RenderFragment ItemTemplate { get; set; } + [Parameter] public RenderFragment ItemTemplate { get; set; } } }