mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-11-29 18:48:50 +08:00
fix(module: table): fix selection (#1973)
* fix(module:table): can not select all * fix(module:table): do not remain selection after change pageIndex * Update table.raz
This commit is contained in:
parent
88fb3b3328
commit
45b47d49b6
@ -127,13 +127,15 @@
|
||||
}
|
||||
<thead class="ant-table-thead">
|
||||
<CascadingValue Name="IsHeader" Value="true" IsFixed>
|
||||
<AntDesign.Internal.TableRow RowAttributes="headerRowAttributes" Table="table">
|
||||
@table.ChildContent(_fieldModel)
|
||||
@if (table.ScrollY != null)
|
||||
{
|
||||
<th class="ant-table-cell @(table._hasFixRight?"ant-table-cell-fix-right":"") ant-table-cell-scrollbar" style="@(table._hasFixRight?"position: sticky; right: 0px;":"")"></th>
|
||||
}
|
||||
</AntDesign.Internal.TableRow>
|
||||
<CascadingValue Value="table" Name="AntDesign.TableRow.Table">
|
||||
<AntDesign.Internal.TableRow TItem="TItem">
|
||||
@table.ChildContent(_fieldModel)
|
||||
@if (table.ScrollY != null)
|
||||
{
|
||||
<th class="ant-table-cell @(table._hasFixRight?"ant-table-cell-fix-right":"") ant-table-cell-scrollbar" style="@(table._hasFixRight?"position: sticky; right: 0px;":"")"></th>
|
||||
}
|
||||
</AntDesign.Internal.TableRow>
|
||||
</CascadingValue>
|
||||
</CascadingValue>
|
||||
</thead>
|
||||
</Template>;
|
||||
@ -170,7 +172,7 @@ RenderFragment<(Table<TItem> table, IEnumerable<TItem> showItems, int level)> bo
|
||||
<Empty Simple />
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
else if (showItems != null && table.ColumnContext.Columns.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < showItems.Count(); i++)
|
||||
@ -188,24 +190,21 @@ RenderFragment<(Table<TItem> table, IEnumerable<TItem> showItems, int level)> bo
|
||||
table._dataSourceCache[cacheKey] = rowData;
|
||||
}
|
||||
var currentRowData = table._dataSourceCache[cacheKey];
|
||||
var childrenData = table.TreeChildren(data);
|
||||
var hasChildren = childrenData?.Any() == true;
|
||||
var childrenData = table.TreeChildren(data);
|
||||
var hasChildren = childrenData?.Any() == true;
|
||||
currentRowData.CacheKey = cacheKey;
|
||||
currentRowData.Level = level;
|
||||
currentRowData.HasChildren = hasChildren;
|
||||
|
||||
var rowAttributes = table.OnRow?.Invoke(currentRowData);
|
||||
if (table.OnRowClick.HasDelegate)
|
||||
{
|
||||
rowAttributes ??= new Dictionary<string, object>();
|
||||
rowAttributes.TryAdd("onclick", ((Action)delegate { table.OnRowClick.InvokeAsync(currentRowData); }));
|
||||
}
|
||||
currentRowData.RowIndex = rowIndex;
|
||||
currentRowData.PageIndex = table.PageIndex;
|
||||
|
||||
<CascadingValue Value="currentRowData" Name="RowData" IsFixed="false">
|
||||
<CascadingValue Value="true" Name="IsBody" IsFixed>
|
||||
<AntDesign.Internal.TableRow RowAttributes="rowAttributes" Level="level" Table="table" RowIndex="rowIndex">
|
||||
@table.ChildContent(data)
|
||||
</AntDesign.Internal.TableRow>
|
||||
<CascadingValue Value="table" Name="AntDesign.TableRow.Table">
|
||||
<AntDesign.Internal.TableRow @key="currentRowData" TItem="TItem">
|
||||
@table.ChildContent(data)
|
||||
</AntDesign.Internal.TableRow>
|
||||
</CascadingValue>
|
||||
</CascadingValue>
|
||||
</CascadingValue>
|
||||
|
||||
|
@ -33,7 +33,7 @@ namespace AntDesign
|
||||
|
||||
// Clear cached items that are not on current page
|
||||
var currentPageCacheKeys = _selection.RowSelections.Select(x => x.RowData.CacheKey).ToHashSet();
|
||||
var deletedCaches = _dataSourceCache.Where(x => x.Value.PageIndex == PageIndex && !currentPageCacheKeys.Contains(x.Key)).ToList();
|
||||
var deletedCaches = _dataSourceCache.Where(x => !currentPageCacheKeys.Contains(x.Key)).ToList();
|
||||
var needInvokeChange = deletedCaches.Any(x => x.Value.Selected);
|
||||
deletedCaches.ForEach(x => _dataSourceCache.Remove(x));
|
||||
|
||||
|
@ -6,12 +6,19 @@
|
||||
|
||||
@if (IsBody)
|
||||
{
|
||||
var rowAttributes = Table.OnRow?.Invoke(RowData);
|
||||
if (Table.OnRowClick.HasDelegate)
|
||||
{
|
||||
rowAttributes ??= new Dictionary<string, object>();
|
||||
rowAttributes.TryAdd("onclick", ((Action)delegate { Table.OnRowClick.InvokeAsync(RowData); }));
|
||||
}
|
||||
|
||||
<CascadingValue Value="_blockColumns" Name="AntDesign.Column.Blocked">
|
||||
<tr @attributes="RowAttributes"
|
||||
data-row-key="@(RowIndex-1)" class="ant-table-row ant-table-row-level-@Level @(RowData.Selected ? "ant-table-row-selected" : "") @Table.RowClassName(RowData) @RowAttributes?.GetValueOrDefault("class")">
|
||||
<tr @attributes="rowAttributes"
|
||||
data-row-key="@(RowData.RowIndex-1)" class="ant-table-row ant-table-row-level-@RowData.Level @(RowData.Selected ? "ant-table-row-selected" : "") @Table.RowClassName(RowData) @rowAttributes?.GetValueOrDefault("class")">
|
||||
<CascadingValue Name="AntDesign.Selection.OnChange"
|
||||
Value="EventCallback.Factory.Create<bool>(this, OnSelectionChange)">
|
||||
<CascadingValue Value="this" TValue="ITableRow" Name="AntDesign.Selection.TableRow" IsFixed>
|
||||
<CascadingValue Value="this" TValue="ITableRow" Name="AntDesign.Selection.TableRow" IsFixed>
|
||||
@ChildContent
|
||||
</CascadingValue>
|
||||
</CascadingValue>
|
||||
@ -20,7 +27,9 @@
|
||||
}
|
||||
else if (IsHeader)
|
||||
{
|
||||
<tr @attributes="RowAttributes">
|
||||
var headerRowAttributes = Table.OnHeaderRow?.Invoke();
|
||||
|
||||
<tr @attributes="headerRowAttributes">
|
||||
<CascadingValue Name="AntDesign.Selection.OnChange"
|
||||
Value="EventCallback.Factory.Create<bool>(this, OnSelectionChange)">
|
||||
@ChildContent
|
||||
@ -33,18 +42,9 @@ else if (IsHeader)
|
||||
@code {
|
||||
bool _blockColumns = false;
|
||||
|
||||
[Parameter]
|
||||
[CascadingParameter(Name = "AntDesign.TableRow.Table")]
|
||||
public Table<TItem> Table { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Dictionary<string, object> RowAttributes { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public int RowIndex { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public int Level { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public RenderFragment ChildContent { get; set; }
|
||||
|
||||
@ -78,7 +78,7 @@ else if (IsHeader)
|
||||
((ITable)Table).Selection.StateHasChanged();
|
||||
}
|
||||
}
|
||||
((ITable)Table).SelectionChanged();
|
||||
((ITable)Table).SelectionChanged();
|
||||
}
|
||||
|
||||
private async void RowDataSelectedChanged(RowData rowData, bool selected)
|
||||
|
Loading…
Reference in New Issue
Block a user