Revert "Progress - select"
This reverts commit d0370a6be479c03517fa76345cef1d4d7bd63ee2.
This commit is contained in:
parent
d0370a6be4
commit
d8a7e0c5cd
@ -2,48 +2,32 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
.selectbox {
|
.selectbox {
|
||||||
width:max-content;
|
width: 150px;
|
||||||
|
height: 100px;
|
||||||
|
background: red;
|
||||||
transition: height 0.05s;
|
transition: height 0.05s;
|
||||||
overflow:hidden;
|
overflow:hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.selectbox:hover {
|
||||||
|
height: 400px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="selectbox @CompiledClassList" style="height:@GetHeight()" @onclick="@HeightOnFull">
|
<div class="selectbox @CompiledClassList">
|
||||||
@if (SearchFieldEnabled && SearchFieldVisibility)
|
@if (SearchFieldEnabled)
|
||||||
{
|
{
|
||||||
//search field
|
//search field
|
||||||
<input type="search" @oninput="@Search" value="@FilterText" />
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<div style="overflow-y:scroll; width:max-content;">
|
@foreach (SelectItem<ValueType> item in Items)
|
||||||
@if(ItemsCount>0)
|
|
||||||
{
|
|
||||||
@foreach (SelectItem<ValueType> item in _itemsToShow)
|
|
||||||
{
|
|
||||||
<Connected.ComponentsN.SelectItem ValueType="ValueType" Text="@item.Text" Value="item.Value" />
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
<div>Ni elementov</div>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
@if (numberOfPages>1)
|
|
||||||
{
|
{
|
||||||
<div style="text-align:center; background-color:aliceblue;">
|
<Connected.ComponentsN.SelectItem ValueType="ValueType" Text="@item.Text" Value="item.Value" />
|
||||||
@if (numberOfPages < 6)
|
}
|
||||||
{
|
|
||||||
@for (int i = 1; i <= numberOfPages; i++)
|
|
||||||
{
|
@if (_pagination()>1)
|
||||||
var index = i;
|
{
|
||||||
<a href="" style ="margin-left:2px; margin-right:2px;" @onclick = "@(()=>SetPage(index))" >@index.ToString()</a>
|
//pagination
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
//pagination of more than 6 pages
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
//pagination
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
@ -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
|
||||||
{
|
{
|
||||||
|
get{
|
||||||
|
if (FilterText.Length > 0)
|
||||||
|
{
|
||||||
|
return _items.Where(i => i.Value.ToString().Contains(FilterText) || i.Text.ToString().Contains(FilterText)).ToList();
|
||||||
|
}
|
||||||
|
return _items;
|
||||||
|
}
|
||||||
set {
|
set {
|
||||||
_originalList = value;
|
_items= value;
|
||||||
_itemsWithFilter= value;
|
|
||||||
_itemsToShow = _itemsWithFilter.Skip(Offset).Take(MaxVisibleItems).ToList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetPage(int page)
|
private List<SelectItem<ValueType>> _items = new List<SelectItem<ValueType>>();
|
||||||
{
|
|
||||||
_selectedPage = page;
|
|
||||||
SetLists();
|
|
||||||
StateHasChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetLists()
|
private int ItemsCount => Items.Count();
|
||||||
{
|
|
||||||
if (FilterText.Length > 0)
|
|
||||||
{
|
|
||||||
_itemsWithFilter = _originalList.Where(i => i.Value.ToString().Contains(FilterText) || i.Text.ToString().Contains(FilterText)).ToList();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_itemsWithFilter = _originalList;
|
|
||||||
}
|
|
||||||
_itemsToShow = _itemsWithFilter.Skip(Offset).Take(MaxVisibleItems).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private int Offset
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return (_selectedPage - 1) * MaxVisibleItems;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private List<SelectItem<ValueType>> _itemsWithFilter;
|
|
||||||
private List<SelectItem<ValueType>> _itemsToShow;
|
|
||||||
private List<SelectItem<ValueType>> _originalList;
|
|
||||||
|
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public EventCallback<string> ValueChanged { get; set; }
|
public int SelectedIndex { get; set; } = 0;
|
||||||
private async Task Search(ChangeEventArgs args)
|
|
||||||
{
|
|
||||||
FilterText = args.Value.ToString();
|
|
||||||
SetLists();
|
|
||||||
_pagination();
|
|
||||||
await ValueChanged.InvokeAsync(args.Value.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private int ItemsCount => _itemsWithFilter.Count();
|
|
||||||
|
|
||||||
private int Height = 20;
|
|
||||||
|
|
||||||
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]
|
[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 result = 0;
|
||||||
|
if (MaxVisibleItems<ItemsCount)
|
||||||
int totalItems = _itemsWithFilter.Count;
|
|
||||||
if (MaxVisibleItems < totalItems)
|
|
||||||
{
|
{
|
||||||
result = (int)(totalItems / MaxVisibleItems);
|
result = (int)(ItemsCount / MaxVisibleItems) + (ItemsCount % MaxVisibleItems);
|
||||||
if (totalItems % MaxVisibleItems > 0) result++;
|
|
||||||
}
|
}
|
||||||
if (!numberOfPages.Equals(result))
|
return result;
|
||||||
{
|
|
||||||
numberOfPages = result;
|
|
||||||
StateHasChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user