|
|
@ -1,7 +1,5 @@
|
|
|
|
using Connected.Utilities;
|
|
|
|
using Connected.Utilities;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Connected.ComponentsN;
|
|
|
|
namespace Connected.ComponentsN;
|
|
|
|
public partial class Select<ValueType>
|
|
|
|
public partial class Select<ValueType>
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -10,113 +8,43 @@ public partial class Select<ValueType>
|
|
|
|
public bool SearchFieldEnabled { get; set; } = false;
|
|
|
|
public bool SearchFieldEnabled { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public int MaxVisibleItems { get; set; } = 5;
|
|
|
|
public int MaxVisibleItems { get; set; } = 7;
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public List<SelectItem<ValueType>> Items
|
|
|
|
public List<SelectItem<ValueType>> Items
|
|
|
|
{
|
|
|
|
{
|
|
|
|
set {
|
|
|
|
get{
|
|
|
|
_originalList = value;
|
|
|
|
|
|
|
|
_itemsWithFilter= value;
|
|
|
|
|
|
|
|
_itemsToShow = _itemsWithFilter.Skip(Offset).Take(MaxVisibleItems).ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void SetPage(int page)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_selectedPage = page;
|
|
|
|
|
|
|
|
SetLists();
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void SetLists()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (FilterText.Length > 0)
|
|
|
|
if (FilterText.Length > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_itemsWithFilter = _originalList.Where(i => i.Value.ToString().Contains(FilterText) || i.Text.ToString().Contains(FilterText)).ToList();
|
|
|
|
return _items.Where(i => i.Value.ToString().Contains(FilterText) || i.Text.ToString().Contains(FilterText)).ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_itemsWithFilter = _originalList;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_itemsToShow = _itemsWithFilter.Skip(Offset).Take(MaxVisibleItems).ToList();
|
|
|
|
return _items;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int Offset
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
get
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return (_selectedPage - 1) * MaxVisibleItems;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set {
|
|
|
|
|
|
|
|
_items= value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private List<SelectItem<ValueType>> _itemsWithFilter;
|
|
|
|
|
|
|
|
private List<SelectItem<ValueType>> _itemsToShow;
|
|
|
|
|
|
|
|
private List<SelectItem<ValueType>> _originalList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
|
|
|
public EventCallback<string> ValueChanged { get; set; }
|
|
|
|
|
|
|
|
private async Task Search(ChangeEventArgs args)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
FilterText = args.Value.ToString();
|
|
|
|
|
|
|
|
SetLists();
|
|
|
|
|
|
|
|
_pagination();
|
|
|
|
|
|
|
|
await ValueChanged.InvokeAsync(args.Value.ToString());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int ItemsCount => _itemsWithFilter.Count();
|
|
|
|
private List<SelectItem<ValueType>> _items = new List<SelectItem<ValueType>>();
|
|
|
|
|
|
|
|
|
|
|
|
private int Height = 20;
|
|
|
|
private int ItemsCount => Items.Count();
|
|
|
|
|
|
|
|
|
|
|
|
private bool SearchFieldVisibility = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void HeightOnFull()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (Height < 400)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SearchFieldVisibility = true;
|
|
|
|
|
|
|
|
Height = 400;
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void HeightToDefault()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (Height > 20)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SearchFieldVisibility = false;
|
|
|
|
|
|
|
|
Height = 20;
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string GetHeight()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Height.ToString() + "px;";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
|
|
|
public int SelectedIndex { get; set; } = 0;
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public string FilterText { get; set; } = string.Empty;
|
|
|
|
public string FilterText { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
private int numberOfPages = 1;
|
|
|
|
private int _pagination()
|
|
|
|
private void _pagination()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int result = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int totalItems = _itemsWithFilter.Count;
|
|
|
|
|
|
|
|
if (MaxVisibleItems < totalItems)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
result = (int)(totalItems / MaxVisibleItems);
|
|
|
|
int result = 0;
|
|
|
|
if (totalItems % MaxVisibleItems > 0) result++;
|
|
|
|
if (MaxVisibleItems<ItemsCount)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!numberOfPages.Equals(result))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
numberOfPages = result;
|
|
|
|
result = (int)(ItemsCount / MaxVisibleItems) + (ItemsCount % MaxVisibleItems);
|
|
|
|
StateHasChanged();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private int _selectedPage = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public string ClassList { get; set; } = string.Empty;
|
|
|
|
public string ClassList { get; set; } = string.Empty;
|
|
|
@ -132,11 +60,4 @@ public partial class Select<ValueType>
|
|
|
|
.Build();
|
|
|
|
.Build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override Task OnParametersSetAsync()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_pagination();
|
|
|
|
|
|
|
|
SetLists();
|
|
|
|
|
|
|
|
return base.OnParametersSetAsync();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|