Skip to content

Commit

Permalink
RadzenTableHeader, RadzenTableHeaderRow and RadzenTableBody added
Browse files Browse the repository at this point in the history
  • Loading branch information
enchev committed Jan 21, 2025
1 parent 097f37b commit 0a802ca
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 45 deletions.
28 changes: 0 additions & 28 deletions Radzen.Blazor/RadzenTable.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,6 @@ public partial class RadzenTable : RadzenComponentWithChildren
[Parameter]
public bool AllowAlternatingRows { get; set; } = true;

List<RadzenTableRow> rows = new List<RadzenTableRow>();

/// <summary>
/// Adds the row.
/// </summary>
/// <param name="row">The row.</param>
public void AddRow(RadzenTableRow row)
{
if (rows.IndexOf(row) == -1)
{
rows.Add(row);
StateHasChanged();
}
}

/// <summary>
/// Removes the row.
/// </summary>
/// <param name="row">The row.</param>
public void RemoveRow(RadzenTableRow row)
{
if (rows.IndexOf(row) != -1)
{
rows.Remove(row);
StateHasChanged();
}
}

/// <inheritdoc />
protected override string GetComponentCssClass()
{
Expand Down
9 changes: 9 additions & 0 deletions Radzen.Blazor/RadzenTableBody.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@inherits RadzenComponentWithChildren
@if (Visible)
{
<tbody @ref="@Element" style="@Style" @attributes="Attributes" class="@GetCssClass()" id="@GetId()">
<CascadingValue Value=this>
@ChildContent
</CascadingValue>
</tbody>
}
39 changes: 39 additions & 0 deletions Radzen.Blazor/RadzenTableBody.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;

namespace Radzen.Blazor
{
/// <summary>
/// RadzenTableBody component.
/// </summary>
public partial class RadzenTableBody : RadzenComponentWithChildren
{
List<RadzenTableRow> rows = new List<RadzenTableRow>();

/// <summary>
/// Adds the row.
/// </summary>
/// <param name="row">The row.</param>
public void AddRow(RadzenTableRow row)
{
if (rows.IndexOf(row) == -1)
{
rows.Add(row);
StateHasChanged();
}
}

/// <summary>
/// Removes the row.
/// </summary>
/// <param name="row">The row.</param>
public void RemoveRow(RadzenTableRow row)
{
if (rows.IndexOf(row) != -1)
{
rows.Remove(row);
StateHasChanged();
}
}
}
}
9 changes: 9 additions & 0 deletions Radzen.Blazor/RadzenTableHeader.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@inherits RadzenComponentWithChildren
@if (Visible)
{
<thead @ref="@Element" style="@Style" @attributes="Attributes" class="@GetCssClass()" id="@GetId()">
<CascadingValue Value=this>
@ChildContent
</CascadingValue>
</thead>
}
39 changes: 39 additions & 0 deletions Radzen.Blazor/RadzenTableHeader.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;

namespace Radzen.Blazor
{
/// <summary>
/// RadzenTableHeader component.
/// </summary>
public partial class RadzenTableHeader : RadzenComponentWithChildren
{
List<RadzenTableHeaderRow> rows = new List<RadzenTableHeaderRow>();

/// <summary>
/// Adds the row.
/// </summary>
/// <param name="row">The row.</param>
public void AddRow(RadzenTableHeaderRow row)
{
if (rows.IndexOf(row) == -1)
{
rows.Add(row);
StateHasChanged();
}
}

/// <summary>
/// Removes the row.
/// </summary>
/// <param name="row">The row.</param>
public void RemoveRow(RadzenTableHeaderRow row)
{
if (rows.IndexOf(row) != -1)
{
rows.Remove(row);
StateHasChanged();
}
}
}
}
2 changes: 1 addition & 1 deletion Radzen.Blazor/RadzenTableHeaderCell.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@inherits RadzenTableCell
@inherits RadzenComponentWithChildren
@if (Visible)
{
<th @ref="@Element" style="@Style" @attributes="Attributes" class="@GetCssClass()" id="@GetId()">
Expand Down
25 changes: 23 additions & 2 deletions Radzen.Blazor/RadzenTableHeaderCell.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,29 @@ namespace Radzen.Blazor
/// <summary>
/// RadzenTableRow component.
/// </summary>
public partial class RadzenTableHeaderCell : RadzenTableCell
public partial class RadzenTableHeaderCell : RadzenComponentWithChildren
{
//
RadzenTableHeaderRow _row;

/// <summary>
/// Gets or sets the row.
/// </summary>
/// <value>The row.</value>
[CascadingParameter]
public RadzenTableHeaderRow Row
{
get
{
return _row;
}
set
{
if (_row != value)
{
_row = value;
_row.AddCell(this);
}
}
}
}
}
9 changes: 9 additions & 0 deletions Radzen.Blazor/RadzenTableHeaderRow.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@inherits RadzenComponentWithChildren
@if (Visible)
{
<tr @ref="@Element" style="@Style" @attributes="Attributes" class="@GetCssClass()" id="@GetId()">
<CascadingValue Value=this>
@ChildContent
</CascadingValue>
</tr>
}
62 changes: 62 additions & 0 deletions Radzen.Blazor/RadzenTableHeaderRow.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;

namespace Radzen.Blazor
{
/// <summary>
/// RadzenTableRow component.
/// </summary>
public partial class RadzenTableHeaderRow : RadzenComponentWithChildren
{
RadzenTableHeader _header;

/// <summary>
/// Gets or sets the table body.
/// </summary>
/// <value>The table body.</value>
[CascadingParameter]
public RadzenTableHeader Header
{
get
{
return _header;
}
set
{
if (_header != value)
{
_header = value;
_header.AddRow(this);
}
}
}

List<RadzenTableHeaderCell> cells = new List<RadzenTableHeaderCell>();

/// <summary>
/// Adds the cell.
/// </summary>
/// <param name="cell">The cell.</param>
public void AddCell(RadzenTableHeaderCell cell)
{
if (cells.IndexOf(cell) == -1)
{
cells.Add(cell);
StateHasChanged();
}
}

/// <summary>
/// Removes the cell.
/// </summary>
/// <param name="cell">The cell.</param>
public void RemoveCell(RadzenTableHeaderCell cell)
{
if (cells.IndexOf(cell) != -1)
{
cells.Remove(cell);
StateHasChanged();
}
}
}
}
16 changes: 8 additions & 8 deletions Radzen.Blazor/RadzenTableRow.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ protected override string GetComponentCssClass()
return "rz-data-row";
}

RadzenTable _table;
RadzenTableBody _body;

/// <summary>
/// Gets or sets the table.
/// Gets or sets the table body.
/// </summary>
/// <value>The table.</value>
/// <value>The table body.</value>
[CascadingParameter]
public RadzenTable Table
public RadzenTableBody Body
{
get
{
return _table;
return _body;
}
set
{
if (_table != value)
if (_body != value)
{
_table = value;
_table.AddRow(this);
_body = value;
_body.AddRow(this);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions RadzenBlazorDemos/Pages/TableConfig.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
</RadzenCard>

<RadzenTable GridLines="@gridLines" AllowAlternatingRows="@allowAlternatingRows">
<thead>
<RadzenTableRow>
<RadzenTableHeader>
<RadzenTableHeaderRow>
@for (var i = 0; i < cols; i++)
{
var col = i;
<RadzenTableHeaderCell>
@($"Column {col}")
</RadzenTableHeaderCell>
}
</RadzenTableRow>
</thead>
<tbody>
</RadzenTableHeaderRow>
</RadzenTableHeader>
<RadzenTableBody>
@for (var i = 0; i < rows; i++)
{
var row = i;
Expand All @@ -36,7 +36,7 @@
}
</RadzenTableRow>
}
</tbody>
</RadzenTableBody>
</RadzenTable>
@code{
Radzen.DataGridGridLines gridLines = Radzen.DataGridGridLines.Default;
Expand Down

0 comments on commit 0a802ca

Please sign in to comment.