Last active
November 12, 2021 14:29
-
-
Save pawelel/fa49b885b8e67d0ec6dd88d4a3e08728 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@if (areas==null) | |
{ | |
<p>wait</p> | |
} | |
else | |
{ | |
<MudTable Items="@locations" T="AreaPlace" Dense="true" @bind-SelectedItem="selectedItem1" Filter="new Func<AreaPlace,bool>(FilterFunc1)"> | |
<ToolBarContent> | |
<MudItem xs="12" md="5"> | |
<MudTextField @bind-Value="searchString1" Placeholder="@L["Find Area"]" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0"></MudTextField> | |
</MudItem> | |
</ToolBarContent> | |
<HeaderContent> | |
<MudTh><b>@L["Area Name"]</b> | |
<MudSelect Clearable="true" T="string" @bind-SelectedValues="AreaHash" MultiSelection="true" Label="@L["Select Areas"]"> | |
@foreach (var area in areas) | |
{ | |
<MudSelectItem T="string" [email protected] /> | |
} | |
</MudSelect> | |
</MudTh> | |
<MudTh><b>@L["Place Name"]</b> | |
<MudSelect Clearable="true" T="string" @bind-SelectedValues="PlaceHash" MultiSelection="true" Label="@L["Select Places"]"> | |
@foreach (var place in places1) | |
{ | |
<MudSelectItem T="string" [email protected] /> | |
} | |
</MudSelect> | |
</MudTh> | |
</HeaderContent> | |
<RowTemplate> | |
@if (SelectAreas(context)&&SelectPlaces(context)) | |
{ | |
<MudTd DataLabel=@L["Area Name"]>@context.AreaName</MudTd> | |
<MudTd DataLabel=@L["Place Name"]>@context.PlaceName</MudTd> | |
} | |
</RowTemplate> | |
</MudTable> | |
} | |
public partial class FilteredMudTable : ComponentBase | |
{ | |
[Inject] | |
DataManager<Area, ApplicationDbContext> AreaManager { get; set; } | |
[Inject] | |
DataManager<Place, ApplicationDbContext> PlaceManager { get; set; } | |
[Inject] | |
private IStringLocalizer<LanguageService> L { get; set; } | |
List<Area> areas = new(); | |
List<Place> places = new(); | |
List<Place> places1 = new(); | |
List<AreaPlace> locations = new(); | |
protected override async Task OnInitializedAsync() | |
{ | |
places=await PlaceManager.Get(include: src => src.Include(p => p.Area)); | |
areas = await AreaManager.Get(); | |
var data = await AreaManager.Get(include: (src => src.Include(a => a.Places))); | |
locations = (from a in data from p in a.Places select new AreaPlace { AreaId=a.Id, AreaName=a.Name, PlaceId=p.Id, PlaceName=p.Name }).ToList(); | |
} | |
private string searchString1 = ""; | |
private string searchString2 = ""; | |
private AreaPlace selectedItem1 = null; | |
private bool FilterFunc1(AreaPlace detail) => FilterFunc(detail, searchString1); | |
private static bool FilterFunc(AreaPlace detail, string searchString) | |
{ | |
if (string.IsNullOrWhiteSpace(searchString)) | |
return true; | |
if (detail.AreaName.Contains(searchString, StringComparison.OrdinalIgnoreCase)) | |
return true; | |
if (detail.PlaceName.Contains(searchString, StringComparison.OrdinalIgnoreCase)) | |
return true; | |
return false; | |
} | |
private IEnumerable<string> PlaceHash { get; set; } = new HashSet<string>() { }; | |
private IEnumerable<string> AreaHash { get; set; } = new HashSet<string>() { }; | |
private bool SelectAreas(AreaPlace areaPlace) | |
{ | |
if (!AreaHash.Any()) | |
{ | |
places1 = places; | |
return true; | |
} | |
foreach (var o in AreaHash) | |
{ | |
if (areaPlace.AreaName==o) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} | |
private bool SelectPlaces(AreaPlace areaPlace) | |
{ | |
List<Place> places2 = new(); | |
if (!PlaceHash.Any()&&!AreaHash.Any()) | |
{ | |
places1=places; | |
return true; | |
} | |
if (!PlaceHash.Any()&&AreaHash.Any()) | |
{ | |
places1=new(); | |
foreach (var a in AreaHash) | |
{ | |
places2 = places.Where(p => p.Area.Name==a).ToList(); | |
places1.AddRange(places2); | |
} | |
return true; | |
} | |
foreach (var o in PlaceHash) | |
{ | |
if (areaPlace.PlaceName==o) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment