- @ChildContent
+@attribute [CascadingTypeParameter(nameof(DataType))]
+@typeparam DataType
+
+
+
+ @foreach (var Item in ItemsToShow)
+ {
+
+
+ @RowTemplate(Item)
+
+
+ @RowDetailTemplate(Item)
+
+
+ }
diff --git a/src/Connected.Components/Components/Grid.razor.cs b/src/Connected.Components/Components/Grid.razor.cs
index fe820dd..9ef8e61 100644
--- a/src/Connected.Components/Components/Grid.razor.cs
+++ b/src/Connected.Components/Components/Grid.razor.cs
@@ -1,40 +1,78 @@
-using Connected.Utilities;
+using Connected.Classes.Grid;
+using Connected.Utilities;
using Microsoft.AspNetCore.Components;
+using Microsoft.Extensions.Options;
+using System.Collections.ObjectModel;
namespace Connected.Components;
-public partial class Grid: ComponentBase
+public partial class Grid
: ComponentBase
{
- public List Rows { get; set; } = new();
-
- [Parameter]
- public RenderFragment? ChildContent { get; set; }
[Parameter]
- public bool Dense { get; set; } = true;
+ public ObservableCollection? Items { get; set; }
+
+ private List? ItemsToShow { get; set; }
[Parameter]
- public bool ContainsImage { get; set; } = true;
+ public RenderFragment? RowTemplate { get; set; }
[Parameter]
- public bool ShowSelect { get; set; } = true;
+ public RenderFragment? RowDetailTemplate { get; set; }
+ [Parameter]
+ public RenderFragment? Img { get; set; }
[Parameter]
- public bool Collapsable { get; set; } = true;
+ public DataGridOptions? Options { get; set; } = null;
[Parameter]
- public string Class { get; set; } = string.Empty;
+ public List? SearchFilters { get; set; } = null;
- private string GridClass
+ public int Count
+ {
+ get
+ {
+ return Items?.Count ?? 0;
+ }
+ }
+
+ [Parameter]
+ public string GridClass { get; set; } = string.Empty;
+ private CssBuilder GridClassList
{
get
{
return new CssBuilder("data-grid")
- .AddClass("dense", Dense)
- .AddClass("image", ContainsImage)
- .AddClass("select", ShowSelect)
- .AddClass("collapse", Collapsable)
- .AddClass(Class)
- .Build();
+ .AddClass("dense", Options?.Dense ?? true)
+ .AddClass("image", Options?.ShowImage ?? true)
+ .AddClass("select", Options?.ShowSelect ?? true)
+ .AddClass("collapse", Options?.Collapsible ?? true)
+ .AddClass(GridClass);
}
}
+
+ public void GetItems()
+ {
+ /*
+ Web API call for item fetch include SearchFilters
+ */
+ SetItemsToShow();
+ }
+
+ private void OnPageChange(int page)
+ {
+ Options.SelectedPage=page;
+
+ //SetItemsToShow();
+ }
+
+ private void SetItemsToShow()
+ {
+ ItemsToShow= Items?.Skip(Options.Offset).Take(Options.ItemsPerPage).ToList() ?? new();
+ }
+
+ protected override async Task OnInitializedAsync()
+ {
+ SetItemsToShow();
+ await base.OnInitializedAsync();
+ }
}
diff --git a/src/Connected.Components/Components/GridRow.razor b/src/Connected.Components/Components/GridRow.razor
index 292cee0..faaf275 100644
--- a/src/Connected.Components/Components/GridRow.razor
+++ b/src/Connected.Components/Components/GridRow.razor
@@ -1,19 +1,32 @@
-
-
-
+@typeparam DataType
+
+
+
+
-
-
-
+
+ @if (ShowImageBlock())
+ {
+
+ }
+
+
+
+
+
+
+ @FixedContent(Item)
+
+
+ @CollapsibleContent(Item)
+
-
-
- @ChildContent
+
diff --git a/src/Connected.Components/Components/GridRow.razor.cs b/src/Connected.Components/Components/GridRow.razor.cs
index edcb6d5..08f4696 100644
--- a/src/Connected.Components/Components/GridRow.razor.cs
+++ b/src/Connected.Components/Components/GridRow.razor.cs
@@ -2,16 +2,23 @@
using Microsoft.AspNetCore.Components;
namespace Connected.Components;
-public partial class GridRow : ComponentBase
+public partial class GridRow
: ComponentBase
{
[CascadingParameter]
- public Grid Parent { get; set; }
+ public Grid Parent { get; set; }
- public List Children { get; set; }
+ [Parameter]
+ public RenderFragment? FixedContent { get; set; }
+
+ [Parameter]
+ public RenderFragment? CollapsibleContent { get; set; }
[Parameter]
- public RenderFragment? ChildContent { get; set; }
+ public string? ImgSrc { get; set; } = null;
+
+ [Parameter]
+ public DataType? Item { get; set; }
[Parameter]
public bool CollapsedItemShown { get; set; } = false;
@@ -22,19 +29,43 @@ public partial class GridRow : ComponentBase
}
[Parameter]
- public string Class { get; set; } = string.Empty;
+ public string RowClass { get; set; } = string.Empty;
+ private CssBuilder GridRowClass
+ {
+ get
+ {
+ return new CssBuilder("data-grid-row-content")
+ .AddClass("show", CollapsedItemShown)
+ .AddClass(RowClass);
+ }
+ }
- [Parameter]
- public GridRowTemplate? Template { get; set; } = null;
+ private CssBuilder CollapsedClass
+ {
+ get
+ {
+ return new CssBuilder()
+ .AddClass("show", CollapsedItemShown)
+ .AddClass(RowClass);
+ }
+ }
- private string GridRowClass
+ private bool ShowImageBlock()
+ {
+ if (string.IsNullOrEmpty(ImgSrc)) return false;
+ bool result = Parent.Options?.ShowImage ?? true;
+ return result;
+ }
+
+ private CssBuilder ImageClass
{
get
{
- return new CssBuilder("data-grid-row-content")
- .AddClass("show",CollapsedItemShown)
- .AddClass(Class)
- .Build();
+ return new CssBuilder()
+ .AddClass("show-image-vertical", Parent.Options.ImagePosition==SmScrn_GridImgPos.Top)
+ .AddClass("show-image", Parent.Options.ImagePosition == SmScrn_GridImgPos.Left)
+
+ .AddClass(RowClass);
}
}
@@ -46,13 +77,19 @@ public partial class GridRow : ComponentBase
await SwitchButtonChangeEvent.InvokeAsync(args);
}
- private string SwitchButtonId = Guid.NewGuid().ToString();
+ private void SetImgSrc()
+ {
+ var colname = Parent.Options.DataSet_ImgColName;
+ var property = typeof(DataType).GetProperty(colname);
+ ImgSrc = property?.GetValue(Item)?.ToString() ?? "";
+ }
protected override async Task OnInitializedAsync()
{
- if (Parent.Rows is null) Parent.Rows = new();
- Parent.Rows.Add(this);
+ SetImgSrc();
await base.OnInitializedAsync();
}
+ private string SwitchButtonId = Guid.NewGuid().ToString();
+
}
\ No newline at end of file
diff --git a/src/Connected.Components/Components/GridRowContent.razor b/src/Connected.Components/Components/GridRowContent.razor
deleted file mode 100644
index db07431..0000000
--- a/src/Connected.Components/Components/GridRowContent.razor
+++ /dev/null
@@ -1,3 +0,0 @@
-
- @ChildContent
-
diff --git a/src/Connected.Components/Components/GridRowContent.razor.cs b/src/Connected.Components/Components/GridRowContent.razor.cs
deleted file mode 100644
index 4c76533..0000000
--- a/src/Connected.Components/Components/GridRowContent.razor.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-using Connected.Utilities;
-using Microsoft.AspNetCore.Components;
-
-namespace Connected.Components;
-public partial class GridRowContent : ComponentBase
-{
- [CascadingParameter]
- public GridRow? Parent { get; set; }
-
- ///
- /// Text shown inside the button
- /// Options: any string variable
- /// Default: string.Empty
- ///
- [Parameter]
- public RenderFragment? ChildContent { get; set; }
-
- ///
- /// Disabled or enabled.
- /// Default: false
- ///
- [Parameter]
- public bool Collapsable { get; set; } = false;
-
- private string GeneratedRowContentClass
- {
- get
- {
- CssBuilder cssBuilder = new CssBuilder("row");
-
- cssBuilder.AddClass("collapsed", Collapsable);
-
- if (Parent is not null)
- {
- cssBuilder.AddClass("show", (Collapsable ? Parent.CollapsedItemShown : false));
- }
-
- return cssBuilder.Build();
- }
- }
-
- protected override async Task OnInitializedAsync()
- {
-
- if (Parent is not null)
- {
- if (Parent.Children is null) Parent.Children = new();
- Parent.Children.Add(this);
- }
- await base.OnInitializedAsync();
- }
-}
-
diff --git a/src/Connected.Components/Enums/Position.cs b/src/Connected.Components/Enums/Position.cs
index 8f187be..eee9a3b 100644
--- a/src/Connected.Components/Enums/Position.cs
+++ b/src/Connected.Components/Enums/Position.cs
@@ -15,3 +15,9 @@ public enum Position
Start,
End
}
+
+public enum SmScrn_GridImgPos
+{
+ Top,
+ Left,
+}