.Format(Field, Format) : Field?.ToString();
+ @if (AppendExpandColumn)
+ {
+
+ @if (Table.RowExpandable(RowData) && (!Table.TreeMode || !RowData.HasChildren))
+ {
+
+ }
+ |
+ }
+
- @if (ColIndex == 1 && Table.TreeMode)
+ @if (ColIndex == Table.TreeExpandIconColumnIndex && Table.TreeMode)
{
@if (RowData.HasChildren)
diff --git a/components/table/ColumnBase.cs b/components/table/ColumnBase.cs
index d26b5095..3d9f93a0 100644
--- a/components/table/ColumnBase.cs
+++ b/components/table/ColumnBase.cs
@@ -65,6 +65,8 @@ namespace AntDesign
public int ColIndex { get; set; }
+ protected bool AppendExpandColumn => Table.HasExpandTemplate && ColIndex == (Table.TreeMode ? Table.TreeExpandIconColumnIndex : Table.ExpandIconColumnIndex);
+
protected string FixedStyle
{
get
@@ -107,7 +109,7 @@ namespace AntDesign
.GetIf(() => $"ant-table-cell-fix-{Fixed}", () => Fixed.IsIn("right", "left"))
.If($"ant-table-cell-fix-right-first", () => Fixed == "right" && Context?.Columns.FirstOrDefault(x => x.Fixed == "right")?.ColIndex == this.ColIndex)
.If($"ant-table-cell-fix-left-last", () => Fixed == "left" && Context?.Columns.LastOrDefault(x => x.Fixed == "left")?.ColIndex == this.ColIndex)
- .If($"ant-table-cell-with-append", () => ColIndex == 1 && Table.TreeMode)
+ .If($"ant-table-cell-with-append", () => ColIndex == Table.TreeExpandIconColumnIndex && Table.TreeMode)
.If($"ant-table-cell-ellipsis", () => Ellipsis)
;
}
diff --git a/components/table/ITable.cs b/components/table/ITable.cs
index 11c6264a..877a33fb 100644
--- a/components/table/ITable.cs
+++ b/components/table/ITable.cs
@@ -1,4 +1,6 @@
-namespace AntDesign
+using AntDesign.TableModels;
+
+namespace AntDesign
{
public interface ITable
{
@@ -14,6 +16,12 @@
internal int ScrollBarWidth { get; }
+ internal int ExpandIconColumnIndex { get; }
+
+ internal int TreeExpandIconColumnIndex { get; }
+
+ internal bool HasExpandTemplate { get; }
+
public TableLocale Locale { get; set; }
internal void SelectionChanged();
@@ -33,5 +41,7 @@
internal void HasFixRight();
internal void TableLayoutIsFixed();
+
+ internal bool RowExpandable(RowData rowData);
}
}
diff --git a/components/table/Table.razor b/components/table/Table.razor
index 46922bf2..f9034711 100644
--- a/components/table/Table.razor
+++ b/components/table/Table.razor
@@ -108,10 +108,6 @@
@
- @if (table.ExpandTemplate != null)
- {
- |
- }
@table.ChildContent(_fieldModel)
@@ -129,12 +125,7 @@ RenderFragment<(Table table, bool header)> colGroup = ctx =>
var table = ctx.table;
var header = ctx.header;
}
-
- @if (table.ExpandTemplate != null)
- {
-
- }
@table.ChildContent(_fieldModel)
@@ -180,17 +171,6 @@ RenderFragment<(Table table, bool header)> colGroup = ctx =>
{ {"onclick", _callbackFactory.Create(table, () => table.RowClick(currentRowData)) } })"
data-row-key="@(rowIndex-1)" class="ant-table-row ant-table-row-level-@level @(currentRowData.Selected ? "ant-table-row-selected" : "")">
- @if (table.ExpandTemplate != null)
- {
-
- @if (table.RowExpandable(currentRowData))
- {
-
- }
- |
- }
@table.ChildContent(data)
@@ -201,7 +181,7 @@ RenderFragment<(Table table, bool header)> colGroup = ctx =>
{
@table.body((table, table.TreeChildren(data), level + 1));
}
- @if (table.ExpandTemplate != null && table.RowExpandable(currentRowData))
+ @if (!hasChildren && table.ExpandTemplate != null && table.RowExpandable(currentRowData))
{
diff --git a/components/table/Table.razor.cs b/components/table/Table.razor.cs
index 2bdc26aa..32dc10c4 100644
--- a/components/table/Table.razor.cs
+++ b/components/table/Table.razor.cs
@@ -91,6 +91,9 @@ namespace AntDesign
[Parameter]
public int IndentSize { get; set; } = 15;
+ [Parameter]
+ public int ExpandIconColumnIndex { get; set; }
+
[Inject]
public DomEventService DomEventService { get; set; }
@@ -109,6 +112,7 @@ namespace AntDesign
private bool _pingRight;
private bool _pingLeft;
private bool _tableLayoutIsFixed;
+ private int _treeExpandIconColumnIndex;
private ElementReference _tableHeaderRef;
private ElementReference _tableBodyRef;
@@ -116,12 +120,13 @@ namespace AntDesign
private bool ServerSide => _total > _dataSourceCount;
bool ITable.TreeMode => _treeMode;
-
int ITable.IndentSize => IndentSize;
-
string ITable.ScrollX => ScrollX;
string ITable.ScrollY => ScrollY;
int ITable.ScrollBarWidth => ScrollBarWidth;
+ int ITable.ExpandIconColumnIndex => ExpandIconColumnIndex;
+ int ITable.TreeExpandIconColumnIndex => _treeExpandIconColumnIndex;
+ bool ITable.HasExpandTemplate => ExpandTemplate != null;
public void ReloadData()
{
@@ -186,6 +191,10 @@ namespace AntDesign
}
_treeMode = TreeChildren != null && (_showItems?.Any(x => TreeChildren(x).Any()) == true);
+ if (_treeMode)
+ {
+ _treeExpandIconColumnIndex = ExpandIconColumnIndex + (_selection != null ? 1 : 0);
+ }
StateHasChanged();
@@ -290,11 +299,6 @@ namespace AntDesign
protected override bool ShouldRender() => this._shouldRender;
- private static void ToggleExpandRow(RowData rowData)
- {
- rowData.Expanded = !rowData.Expanded;
- }
-
private void RowClick(RowData item)
{
if (OnRowClick.HasDelegate)
@@ -367,5 +371,10 @@ namespace AntDesign
await JsInvokeAsync(JSInteropConstants.UnbindTableHeaderAndBodyScroll, _tableBodyRef);
}
}
+
+ bool ITable.RowExpandable(RowData rowData)
+ {
+ return RowExpandable(rowData as RowData);
+ }
}
}
| |