public SearchableGroupedList(ObservableList <T> originalItems, Func <string, IComponent> groupedItemHeaderGenerator, params UnitSize[] columns) { _groupedItemHeaderGenerator = groupedItemHeaderGenerator; _searchBox = new SearchBox().Underlined().SetPlaceholder("Type to search").SearchAsYouType().Width(100.px()).Grow(); _list = ItemsList(new IComponent[0], columns); _groupComparer = StringComparer.OrdinalIgnoreCase; Items = new ObservableList <IComponent>(); _defered = Defer( Items, item => { var searchTerms = (_searchBox.Text ?? "").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var filteredItems = originalItems.OfType <T>().Where(i => searchTerms.Length == 0 || searchTerms.All(st => i.IsMatch(st))).ToArray(); AddGroupedItems(filteredItems, _list.Items, isGrid: (columns is object && columns.Length > 1)); return(_list.Stretch().AsTask()); } ) .WidthStretch() .Grow(); originalItems.Observe(_ => _defered.Refresh()); _searchBox.OnSearch((_, __) => _defered.Refresh()); _searchBoxContainer = Stack().Horizontal().WidthStretch().Children(_searchBox).AlignItems(ItemAlign.Center); _searchBoxContainerComponents = new List <IComponent> { _searchBox }; _stack = Stack().Children(_searchBoxContainer, _defered.Scroll()).WidthStretch().MaxHeight(100.percent()); }
public SearchableList(ObservableList <T> items, params UnitSize[] columns) { Items = items ?? new ObservableList <T>(); _searchBox = new SearchBox().Underlined().SetPlaceholder("Type to search").SearchAsYouType().Width(100.px()).Grow(); _list = ItemsList(new IComponent[0], columns); _defered = Defer( Items, item => { var searchTerms = (_searchBox.Text ?? "").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var filteredItems = Items.Where(i => searchTerms.Length == 0 || searchTerms.All(st => i.IsMatch(st))).Select(i => i.Render()).ToArray(); _list.Items.Clear(); if (filteredItems.Any()) { _list.Items.AddRange(filteredItems); } if (filteredItems.Length >= _minimumItemsToShowBox) { _searchBox.Show(); } else { _searchBox.Collapse(); } return(_list.Stretch().AsTask()); } ) .WidthStretch() .Grow(1); _searchBox.OnSearch((_, __) => _defered.Refresh()); _searchBoxContainer = Stack().Horizontal().WidthStretch().Children(_searchBox).AlignItems(ItemAlign.Center); _searchBoxContainerComponents = new List <IComponent>() { _searchBox }; _stack = Stack().Children(_searchBoxContainer, _defered.Scroll()).WidthStretch().MaxHeight(100.percent()); }
public SearchableList(ObservableList <T> items, UnitSize[] columns) { Items = items ?? new ObservableList <T>(); _searchBox = new SearchBox().Underlined().SetPlaceholder("Type to search").SearchAsYouType().WidthStretch(); _list = ItemsList(new IComponent[0], columns); _defered = Defer(Items, item => { var searchTerm = _searchBox.Text; var filteredItems = Items.Where(i => string.IsNullOrWhiteSpace(searchTerm) || i.IsMatch(searchTerm)).Select(i => i.Render()).ToArray(); _list.Items.Clear(); if (filteredItems.Any()) { _list.Items.AddRange(filteredItems); } return(_list.Stretch().AsTask()); }).WidthStretch().Height(100.px()).Grow(1); _searchBox.OnSearch((_, __) => _defered.Refresh()); _stack = Stack().Children(_searchBox, _defered.Scroll()).WidthStretch().MaxHeight(100.percent()); }
public ItemsList WithEmptyMessage(Func <IComponent> emptyListMessageGenerator) { _emptyListMessageGenerator = emptyListMessageGenerator ?? throw new ArgumentNullException(nameof(emptyListMessageGenerator)); _defered.Refresh(); return(this); }
public SearchableList <T> WithNoResultsMessage(Func <IComponent> emptyListMessageGenerator) { _list.WithEmptyMessage(emptyListMessageGenerator ?? throw new ArgumentNullException(nameof(emptyListMessageGenerator))); _defered.Refresh(); return(this); }