|
| 1 | +@namespace BootstrapBlazor.Components |
| 2 | +@using Microsoft.AspNetCore.Components.Web.Virtualization |
| 3 | +@typeparam TValue |
| 4 | +@inherits SelectBase<List<TValue>> |
| 5 | +@attribute [BootstrapModuleAutoLoader("Select/MultiSelect.razor.js", JSObjectReference = true)] |
| 6 | + |
| 7 | +@if (IsShowLabel) |
| 8 | +{ |
| 9 | + <BootstrapLabel required="@Required" for="@Id" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText"></BootstrapLabel> |
| 10 | +} |
| 11 | +<div @attributes="@AdditionalAttributes" class="@ClassString" id="@Id" data-bb-scroll-behavior="@ScrollIntoViewBehaviorString"> |
| 12 | + <div class="@ToggleClassString" data-bs-toggle="@ToggleString" data-bs-placement="@PlacementString" data-bs-offset="@OffsetString" data-bs-auto-close="outside" data-bs-custom-class="@CustomClassString" tabindex="0"> |
| 13 | + <div class="@PlaceHolderClassString">@PlaceHolder</div> |
| 14 | + <div class="multi-select-items"> |
| 15 | + @if (DisplayTemplate != null) |
| 16 | + { |
| 17 | + @DisplayTemplate(SelectedItems) |
| 18 | + } |
| 19 | + else |
| 20 | + { |
| 21 | + foreach (var item in SelectedItems) |
| 22 | + { |
| 23 | + if (ShowCloseButton) |
| 24 | + { |
| 25 | + <div class="multi-select-item-group"> |
| 26 | + <DynamicElement TagName="span" class="multi-select-close" |
| 27 | + TriggerClick="@(!IsPopover)" OnClick="() => ToggleRow(item)"> |
| 28 | + <i class="@CloseButtonIcon"></i> |
| 29 | + </DynamicElement> |
| 30 | + <span class="multi-select-item">@item.Text</span> |
| 31 | + </div> |
| 32 | + } |
| 33 | + else |
| 34 | + { |
| 35 | + <span class="multi-select-item">@item.Text</span> |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + </div> |
| 40 | + @if (!IsSingleLine) |
| 41 | + { |
| 42 | + <span class="@AppendClassString"><i class="@DropdownIcon"></i></span> |
| 43 | + } |
| 44 | + </div> |
| 45 | + @if (GetClearable()) |
| 46 | + { |
| 47 | + <span class="@ClearClassString" @onclick="OnClearValue"><i class="@ClearIcon"></i></span> |
| 48 | + } |
| 49 | + <div class="@DropdownMenuClassString"> |
| 50 | + @if (ShowSearch) |
| 51 | + { |
| 52 | + <div class="dropdown-menu-search"> |
| 53 | + <input type="text" class="search-text form-control" autocomplete="off" value="@SearchText" aria-label="search" /> |
| 54 | + <i class="@SearchIconString"></i> |
| 55 | + <i class="@SearchLoadingIconString"></i> |
| 56 | + </div> |
| 57 | + } |
| 58 | + @if (ShowToolbar) |
| 59 | + { |
| 60 | + <div class="toolbar"> |
| 61 | + @if (ShowDefaultButtons) |
| 62 | + { |
| 63 | + <DynamicElement TagName="button" type="button" class="btn" OnClick="SelectAll">@SelectAllText</DynamicElement> |
| 64 | + <DynamicElement TagName="button" type="button" class="btn" OnClick="InvertSelect">@ReverseSelectText</DynamicElement> |
| 65 | + <DynamicElement TagName="button" type="button" class="btn" OnClick="Clear">@ClearText</DynamicElement> |
| 66 | + } |
| 67 | + @ButtonTemplate |
| 68 | + </div> |
| 69 | + } |
| 70 | + @if (IsVirtualize) |
| 71 | + { |
| 72 | + <div class="dropdown-menu-body dropdown-virtual"> |
| 73 | + @if (OnQueryAsync == null) |
| 74 | + { |
| 75 | + <Virtualize ItemSize="RowHeight" OverscanCount="OverscanCount" Items="@GetVirtualItems()" ChildContent="RenderRow"> |
| 76 | + </Virtualize> |
| 77 | + } |
| 78 | + else |
| 79 | + { |
| 80 | + <Virtualize ItemSize="RowHeight" OverscanCount="OverscanCount" ItemsProvider="LoadItems" |
| 81 | + Placeholder="RenderPlaceHolderRow" ItemContent="RenderRow" @ref="_virtualizeElement"> |
| 82 | + </Virtualize> |
| 83 | + } |
| 84 | + </div> |
| 85 | + } |
| 86 | + else if (Rows.Count == 0) |
| 87 | + { |
| 88 | + <div class="dropdown-item">@NoSearchDataText</div> |
| 89 | + } |
| 90 | + else |
| 91 | + { |
| 92 | + <div class="dropdown-menu-body"> |
| 93 | + @foreach (var itemGroup in Rows.GroupBy(i => i.GroupName)) |
| 94 | + { |
| 95 | + if (!string.IsNullOrEmpty(itemGroup.Key)) |
| 96 | + { |
| 97 | + if (GroupItemTemplate != null) |
| 98 | + { |
| 99 | + @GroupItemTemplate(itemGroup.Key) |
| 100 | + } |
| 101 | + else |
| 102 | + { |
| 103 | + <Divider Text="@itemGroup.Key" /> |
| 104 | + } |
| 105 | + } |
| 106 | + @foreach (var item in itemGroup) |
| 107 | + { |
| 108 | + @RenderRow(item) |
| 109 | + } |
| 110 | + |
| 111 | + if (!string.IsNullOrEmpty(itemGroup.Key)) |
| 112 | + { |
| 113 | + if (GroupItemTemplate != null) |
| 114 | + { |
| 115 | + @GroupItemTemplate(itemGroup.Key) |
| 116 | + } |
| 117 | + else |
| 118 | + { |
| 119 | + <Divider Text="@itemGroup.Key" /> |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | + </div> |
| 124 | + } |
| 125 | + </div> |
| 126 | +</div> |
| 127 | + |
| 128 | +@code { |
| 129 | + RenderFragment<SelectedItem<TValue>> RenderRow => item => |
| 130 | + @<DynamicElement OnClick="() => ToggleRow(item)" TriggerClick="@CheckCanTrigger(item)" class="@GetItemClassString(item)"> |
| 131 | + <div class="multi-select-item"> |
| 132 | + <div class="form-check"> |
| 133 | + <input class="form-check-input" type="checkbox" disabled="@CheckCanSelect(item)" checked="@GetCheckedString(item)" /> |
| 134 | + </div> |
| 135 | + @if (ItemTemplate != null) |
| 136 | + { |
| 137 | + @ItemTemplate(item) |
| 138 | + } |
| 139 | + else if (IsMarkupString) |
| 140 | + { |
| 141 | + @((MarkupString)item.Text) |
| 142 | + } |
| 143 | + else |
| 144 | + { |
| 145 | + <span>@item.Text</span> |
| 146 | + } |
| 147 | + </div> |
| 148 | + </DynamicElement>; |
| 149 | + |
| 150 | + RenderFragment<PlaceholderContext> RenderPlaceHolderRow => context => |
| 151 | + @<div class="dropdown-item"> |
| 152 | + <div class="is-ph"></div> |
| 153 | + </div>; |
| 154 | +} |
0 commit comments