You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Components/Components/Table/Table.razor

246 lines
10 KiB

@namespace Connected.Components
@using Connected.Utilities;
@inherits TableBase
@typeparam T
<div @attributes="UserAttributes" class="@Classname" style="@Style">
@if (Items != null || ServerData != null)
{
<CascadingValue Value="TableContext" IsFixed="true">
@if (ToolBarContent != null)
{
<ToolBar Class="mud-table-toolbar">
@ToolBarContent
</ToolBar>
}
@if (Context.SortLabels.Any())
{
<div Class="mud-table-smalldevices-sortselect">
<CascadingValue Name="SubscribeToParentForm" Value="false" IsFixed>
<Select Value="@Context.CurrentSortLabel" Label="@SortLabel" ValueChanged="@(v => Context.SetSortFunc(v, override_direction_none: true))" T="TableSortLabel<T>">
@foreach (var label in Context.SortLabels)
{
<SelectItem Value="@label">@label.ChildContent</SelectItem>
}
</Select>
</CascadingValue>
</div>
}
<div class="mud-table-container" style="@TableStyle @(GetHorizontalScrollbarStyle())">
<table class="mud-table-root">
@if (ColGroup != null)
{
<colgroup>
@ColGroup
</colgroup>
}
@if (HeaderContent != null || Columns != null)
{
<thead class="@HeadClassname">
@if (CustomHeader)
{
@HeaderContent
}
else
{
<THeadRow IsCheckable="MultiSelection" IsExpandable="@(GroupBy?.Expandable ?? false)">
@if (HeaderContent != null)
{
@HeaderContent
}
@if (Columns != null)
{
<CascadingValue Value="ColumnBase.Rendermode.Header" Name="Mode">
@Columns(Def)
</CascadingValue>
}
</THeadRow>
}
</thead>
}
<tbody class="mud-table-body">
@if (Loading)
{
<tr>
<td colspan="1000" class="@(CurrentPageItems.Count() > 0 || LoadingContent != null ? "mud-table-loading" : "")">
<ProgressLinear Color="@LoadingProgressColor" Class="mud-table-loading-progress" Indeterminate="true" />
</td>
</tr>
}
@if(GroupBy != null)
{
@foreach (var group in GroupItemsPage)
{
<TableGroupRow GroupDefinition="GroupBy" Items="group" IsCheckable="MultiSelection"
HeaderClass="@GroupHeaderClass" HeaderStyle="@GroupHeaderStyle"
FooterClass="@GroupFooterClass" FooterStyle="@GroupFooterStyle"
HeaderTemplate="@GroupHeaderTemplate" FooterTemplate="@GroupFooterTemplate" T="T" />
}
}
else
{
@if (CurrentPageItems != null && CurrentPageItems.Count() > 0)
{
var rowIndex = 0;
<Virtualize IsEnabled="@Virtualize" Items="@CurrentPageItems?.ToList()" Context="item">
@{ var rowClass = new CssBuilder(RowClass).AddClass(RowClassFunc?.Invoke(item, rowIndex)).Build(); }
@{ var rowStyle = new StyleBuilder().AddStyle(RowStyle).AddStyle(RowStyleFunc?.Invoke(item, rowIndex)).Build(); }
<Tr Class="@rowClass" Style="@rowStyle" Item="item" @key="item" IsCheckable="MultiSelection" IsEditable="IsEditable"
IsChecked="@(Context.Selection.Contains(item))"
IsCheckedChanged="((value) => { var x = item; OnRowCheckboxChanged(value, x); })">
@if ((!ReadOnly) && IsEditable && object.Equals(_editingItem, item))
{
<CascadingValue Value="@Validator" IsFixed="true">
@if(RowEditingTemplate != null)
{
@RowEditingTemplate(item)
}
@if (Columns != null)
{
<CascadingValue Value="ColumnBase.Rendermode.Edit" Name="Mode">
@Columns(item)
</CascadingValue>
}
</CascadingValue>
}
else
{
if (RowTemplate != null)
{
@RowTemplate(item)
}
@if (Columns != null)
{
<CascadingValue Value="ColumnBase.Rendermode.Item" Name="Mode">
@Columns(item)
</CascadingValue>
}
}
</Tr>
@if (ChildRowContent != null)
{
@ChildRowContent(item)
}
@{ rowIndex++; }
</Virtualize>
}
}
@if(!(CurrentPageItems != null && CurrentPageItems.Count() > 0)
&& (Loading ? LoadingContent != null : NoRecordsContent != null)
)
{
<tr>
<th colspan="1000" class="mud-table-empty-row">
<div Class="my-3">
@if(Loading)
{
@LoadingContent
}
else
{
@NoRecordsContent
}
</div>
</th>
</tr>
}
</tbody>
@if (FooterContent != null || Columns != null)
{
<tfoot class="@FootClassname">
@if (CustomFooter)
{
@FooterContent
}
else
{
<TFootRow IsCheckable="MultiSelection" IsExpandable="@(GroupBy?.Expandable ?? false)">
@if (@FooterContent != null)
{
@FooterContent
}
@if (Columns != null)
{
<CascadingValue Value="ColumnBase.Rendermode.Footer" Name="Mode">
@Columns(Def)
</CascadingValue>
}
</TFootRow>
}
</tfoot>
}
</table>
</div>
@if (PagerContent != null)
{
<div class="mud-table-pagination">
@PagerContent
</div>
}
</CascadingValue>
}
</div>
@code
{
// moved to code to avoid repeatedly code on markup block
internal RenderFragment RenderRows(IEnumerable<T> source, string customClass = null, bool isExpandable = false)
{
var rowIndex = 0;
RenderFragment rootNode =
@<text>
<Virtualize IsEnabled="@Virtualize" Items="@source?.ToList()" Context="item" ChildContent="@child()">
</Virtualize>
</text>;
RenderFragment<T> child() => item =>
@<text>
@{
var rowClass = new CssBuilder(RowClass).AddClass(RowClassFunc?.Invoke(item, rowIndex)).AddClass(customClass, ! string.IsNullOrEmpty("mud-table-row-group-indented-1")).Build();
var rowStyle = new StyleBuilder().AddStyle(RowStyle).AddStyle(RowStyleFunc?.Invoke(item, rowIndex)).Build();
}
<Tr Class="@rowClass" Style="@rowStyle" Item="item" @key="item" IsCheckable="MultiSelection" IsEditable="IsEditable" IsExpandable="isExpandable"
IsCheckedChanged="((value) => { var x = item; OnRowCheckboxChanged(value, x); })">
@if ((!ReadOnly) && IsEditable && object.Equals(_editingItem, item))
{
<CascadingValue Value="@Validator" IsFixed="true">
@if(RowEditingTemplate != null)
{
@RowEditingTemplate(item)
}
@if (Columns != null)
{
<CascadingValue Value="ColumnBase.Rendermode.Edit" Name="Mode">
@Columns(item)
</CascadingValue>
}
</CascadingValue>
}
else
{
if (RowTemplate != null)
{
@RowTemplate(item)
}
@if (Columns != null)
{
<CascadingValue Value="ColumnBase.Rendermode.Item" Name="Mode">
@Columns(item)
</CascadingValue>
}
}
</Tr>
@if (ChildRowContent != null)
{
@ChildRowContent(item)
}
@{rowIndex++;}
</text>
;
return rootNode;
}
}