// For end-users to let SelectionMode handle what to do. public void HandleClick(TItem item) { bool hasChanged = false; if (SelectionMode == SelectionMode.Multiple) { hasChanged = true; if (selectedItems.Contains(item)) { selectedItems.Remove(item); } else { selectedItems.Add(item); } } else if (SelectionMode == SelectionMode.Single) { if (!selectedItems.Contains(item)) { hasChanged = true; selectedItems.Clear(); selectedItems.Add(item); } } if (hasChanged) { doNotRenderOnce = true; selectedItemsSubject.OnNext(selectedItems); SelectionChanged.InvokeAsync(new Selection <TItem>(selectedItems)); } }
public void ClearSelection() { if (selectedItems.Count > 0) { selectedItems.Clear(); SelectionChanged.InvokeAsync(new Selection <TItem>(selectedItems)); } }
async void Update() { if (IsValid()) { ShowErrorMessage = false; await SelectionChanged.InvokeAsync(new Tuple <DateTime, DateTime>(StartDate, EndDate)); } }
public void ClearSelection() { if (selectedItems.Count > 0) { selectedItems.Clear(); doNotRenderOnce = true; selectedItemsSubject.OnNext(selectedItems); SelectionChanged.InvokeAsync(new Selection <TItem>(selectedItems)); } }
/// <summary> /// Clears the current selection. /// </summary> public async Task ClearSelectionAsync() { if (Selection.Count > 0) { Selection.Clear(); await SelectionChanged.InvokeAsync(null).ConfigureAwait(true); StateHasChanged(); } }
public void RemoveItems(IEnumerable <TItem> items) { foreach (var item in items) { selectedItems.Remove(item); } if (items != null && items.Count() > 0) { SelectionChanged.InvokeAsync(new Selection <TItem>(selectedItems)); } }
public void RemoveItems(IEnumerable <TItem> items) { foreach (var item in items) { selectedItems.Remove(item); } if (items != null && items.Count() > 0) { doNotRenderOnce = true; selectedItemsSubject.OnNext(selectedItems); SelectionChanged.InvokeAsync(new Selection <TItem>(selectedItems)); } }
public void AddItems(IEnumerable <TItem> items) { foreach (var item in items) { if (!selectedItems.Contains(item)) { selectedItems.Add(item); } } if (items != null && items.Count() > 0) { SelectionChanged.InvokeAsync(new Selection <TItem>(selectedItems)); } }
public void AddAndRemoveItems(IEnumerable <TItem> itemsToAdd, IEnumerable <TItem> itemsToRemove) { foreach (var item in itemsToAdd) { if (!selectedItems.Contains(item)) { selectedItems.Add(item); } } foreach (var item in itemsToRemove) { selectedItems.Remove(item); } if ((itemsToAdd != null && itemsToAdd.Count() > 0) || (itemsToRemove != null && itemsToRemove.Count() > 0)) { SelectionChanged.InvokeAsync(new Selection <TItem>(selectedItems)); } }
protected override async Task OnParametersSetAsync() { if (Selection != null && Selection.SelectedItems != selectedItems) { selectedItems = new System.Collections.Generic.HashSet <TItem>(Selection.SelectedItems); } if (SelectionMode == SelectionMode.Single && selectedItems.Count() > 1) { selectedItems.Clear(); await SelectionChanged.InvokeAsync(new Selection <TItem>(selectedItems)); } else if (SelectionMode == SelectionMode.None && selectedItems.Count() > 0) { selectedItems.Clear(); await SelectionChanged.InvokeAsync(new Selection <TItem>(selectedItems)); } await base.OnParametersSetAsync(); }
// For end-users to let SelectionMode handle what to do. public void HandleToggle(TItem item) { bool hasChanged = false; switch (SelectionMode) { case SelectionMode.Multiple: hasChanged = true; if (selectedItems.Contains(item)) { selectedItems.Remove(item); } else { selectedItems.Add(item); } break; case SelectionMode.Single: hasChanged = true; if (selectedItems.Contains(item)) { selectedItems.Remove(item); } else { selectedItems.Clear(); selectedItems.Add(item); } break; case SelectionMode.None: break; } if (hasChanged) { doNotRenderOnce = true; selectedItemsSubject.OnNext(selectedItems); SelectionChanged.InvokeAsync(new Selection <TItem>(selectedItems)); } }
/// <summary> /// For DetailsRow /// </summary> /// <param name="item"></param> /// <param name="asSingle">On click, force list to select one even if set to multiple</param> public void SelectItem(TItem item, bool asSingle = false) { bool hasChanged = false; if (SelectionMode == SelectionMode.Multiple && !asSingle) { hasChanged = true; if (selectedItems.Contains(item)) { selectedItems.Remove(item); } else { selectedItems.Add(item); } } else if (SelectionMode == SelectionMode.Multiple && asSingle) { //same as single except we need to clear other items if they are selected, too hasChanged = true; selectedItems.Clear(); selectedItems.Add(item); } else if (SelectionMode == SelectionMode.Single) { if (!selectedItems.Contains(item)) { hasChanged = true; selectedItems.Clear(); selectedItems.Add(item); } } if (hasChanged) { doNotRenderOnce = true; selectedItemsSubject.OnNext(selectedItems); SelectionChanged.InvokeAsync(new Selection <TItem>(selectedItems)); } }
private async Task OnKeyDownAsync(KeyboardEventArgs args) { if (IsEditing) { switch (args.Code) { case "Escape": CancelEdit(); break; case "Enter": case "Return": await CommitEditAsync().ConfigureAwait(true); break; } } else { switch (args.Code) { case "F2": await BeginEditAsync().ConfigureAwait(true); break; case "KeyA": if (args.CtrlKey && SelectionMode == TableSelectionMode.Multiple) { await ClearSelectionAsync().ConfigureAwait(true); Selection.AddRange(ItemsToDisplay.Select(x => KeyField !(x).ToString())); await SelectionChanged.InvokeAsync(null).ConfigureAwait(true); } break; case "ArrowUp": case "ArrowDown": if (Selection.Count == 1 && KeyField != null) { var items = ItemsToDisplay.ToList(); var item = items.Find(x => KeyField(x).ToString() == Selection[0]); if (item != null) { var idx = items.IndexOf(item); if (args.Code == "ArrowUp" && idx > 0) { Selection.Clear(); Selection.Add(KeyField(items[idx - 1]).ToString()); } else if (args.Code == "ArrowDown" && idx < items.Count - 1) { Selection.Clear(); Selection.Add(KeyField(items[idx + 1]).ToString()); } } } break; } } await KeyDown.InvokeAsync(args).ConfigureAwait(true); }
private async Task OnRowMouseDownAsync(MouseEventArgs args, TItem item) { if (SelectionMode != TableSelectionMode.None) { var key = KeyField !(item)?.ToString(); if (key != null) { var alreadySelected = Selection.Contains(key); // begin edit mode? if (AllowEdit && !IsEditing && Selection.Count == 1 && alreadySelected && !args.CtrlKey && args.Button == 0) { _editTimer?.Change(500, Timeout.Infinite); } else { if (SelectionMode == TableSelectionMode.Single) { if (!alreadySelected) { Selection.Clear(); Selection.Add(key); await SelectionChanged.InvokeAsync(null).ConfigureAwait(true); } } else if (SelectionMode == TableSelectionMode.Multiple) { if (args.ShiftKey && Selection.Count > 0) // range selection (from last selected to row clicked on) { Selection.RemoveRange(0, Selection.Count - 1); var idxFrom = ItemsToDisplay.FindIndex(x => KeyField !(x)?.ToString() == Selection[0]); var idxTo = ItemsToDisplay.FindIndex(x => KeyField !(x)?.ToString() == key); if (idxFrom > -1 && idxTo > -1) { Selection.Clear(); Selection.AddRange(ItemsToDisplay .GetRange(Math.Min(idxFrom, idxTo), (Math.Max(idxFrom, idxTo) - Math.Min(idxFrom, idxTo)) + 1) .Select(x => KeyField !(x).ToString())); await SelectionChanged.InvokeAsync(null).ConfigureAwait(true); } } else if (args.CtrlKey) // toggle selection { if (alreadySelected) { Selection.Remove(key); } else { Selection.Add(key); } await SelectionChanged.InvokeAsync(null).ConfigureAwait(true); } else if (!alreadySelected) // single selection { Selection.Clear(); Selection.Add(key); await SelectionChanged.InvokeAsync(null).ConfigureAwait(true); } } } } } }