diff --git a/src/Connected.Components/ComponentsN/Select.razor b/src/Connected.Components/ComponentsN/Select.razor
index eddab26..c4c3e62 100644
--- a/src/Connected.Components/ComponentsN/Select.razor
+++ b/src/Connected.Components/ComponentsN/Select.razor
@@ -2,48 +2,32 @@
-
- @if (SearchFieldEnabled && SearchFieldVisibility)
+
+ @if (SearchFieldEnabled)
{
//search field
-
}
-
- @if(ItemsCount>0)
- {
- @foreach (SelectItem
item in _itemsToShow)
- {
-
- }
- } else
- {
- Ni elementov
- }
-
+ @foreach (SelectItem
item in Items)
+ {
+
+ }
- @if (numberOfPages>1)
+ @if (_pagination()>1)
{
-
- @if (numberOfPages < 6)
- {
- @for (int i = 1; i <= numberOfPages; i++)
- {
- var index = i;
-
SetPage(index))" >@index.ToString()
- }
- } else
- {
- //pagination of more than 6 pages
- }
-
- //pagination
+ //pagination
}
diff --git a/src/Connected.Components/ComponentsN/Select.razor.cs b/src/Connected.Components/ComponentsN/Select.razor.cs
index 45db35b..7480c9c 100644
--- a/src/Connected.Components/ComponentsN/Select.razor.cs
+++ b/src/Connected.Components/ComponentsN/Select.razor.cs
@@ -1,7 +1,5 @@
using Connected.Utilities;
using Microsoft.AspNetCore.Components;
-using Microsoft.AspNetCore.Components.Web;
-
namespace Connected.ComponentsN;
public partial class Select
{
@@ -10,113 +8,43 @@ public partial class Select
public bool SearchFieldEnabled { get; set; } = false;
[Parameter]
- public int MaxVisibleItems { get; set; } = 5;
+ public int MaxVisibleItems { get; set; } = 7;
[Parameter]
public List> Items
{
+ get{
+ if (FilterText.Length > 0)
+ {
+ return _items.Where(i => i.Value.ToString().Contains(FilterText) || i.Text.ToString().Contains(FilterText)).ToList();
+ }
+ return _items;
+ }
set {
- _originalList = value;
- _itemsWithFilter= value;
- _itemsToShow = _itemsWithFilter.Skip(Offset).Take(MaxVisibleItems).ToList();
+ _items= value;
}
}
- private void SetPage(int page)
- {
- _selectedPage = page;
- SetLists();
- StateHasChanged();
- }
+ private List> _items = new List>();
- private void SetLists()
- {
- 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> _itemsWithFilter;
- private List> _itemsToShow;
- private List> _originalList;
+ private int ItemsCount => Items.Count();
+
[Parameter]
- public EventCallback 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 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;";
- }
-
+ public int SelectedIndex { get; set; } = 0;
[Parameter]
public string FilterText { get; set; } = string.Empty;
- private int numberOfPages = 1;
- private void _pagination()
+ private int _pagination()
{
- int result = 1;
-
- int totalItems = _itemsWithFilter.Count;
- if (MaxVisibleItems < totalItems)
+ int result = 0;
+ if (MaxVisibleItems 0) result++;
+ result = (int)(ItemsCount / MaxVisibleItems) + (ItemsCount % MaxVisibleItems);
}
- if (!numberOfPages.Equals(result))
- {
- numberOfPages = result;
- StateHasChanged();
- }
-
+ return result;
}
- private int _selectedPage = 1;
[Parameter]
public string ClassList { get; set; } = string.Empty;
@@ -132,11 +60,4 @@ public partial class Select
.Build();
}
}
-
- protected override Task OnParametersSetAsync()
- {
- _pagination();
- SetLists();
- return base.OnParametersSetAsync();
- }
}