Beispiel #1
0
        private async Task HandleSelectOrMultiSelectDataItemClick(TItem clickedDataItem)
        {
            Contract.Requires(SelectionEnabled || MultiSelectionEnabled);

            if (SelectionEnabled)
            {
                await SetSelectedDataItemWithEventCallback(clickedDataItem);
            }
            else             // MultiSelectionEnabled
            {
                var selectedDataItems = SelectedDataItems?.ToHashSet() ?? new HashSet <TItem>();
                if (selectedDataItems.Add(clickedDataItem) ||              // when the item was added
                    selectedDataItems.Remove(clickedDataItem))                        // or removed... But because of || item removal is performed only when the item was not added!
                {
                    await SetSelectedDataItemsWithEventCallback(selectedDataItems);
                }
            }
        }
Beispiel #2
0
        protected override CellTemplate GetItemCellTemplate(TItem item)
        {
            return(new CellTemplate
            {
                CssClass = "text-center",
                Template = (RenderTreeBuilder builder) =>
                {
                    builder.OpenElement(100, "input");
                    builder.AddAttribute(101, "type", "checkbox");
                    builder.AddAttribute(102, "class", "form-check-input");

                    bool selected = SelectedDataItems?.Contains(item) ?? false;
                    builder.AddAttribute(103, "checked", selected);
                    builder.AddAttribute(104, "onchange", EventCallback.Factory.Create <ChangeEventArgs>(this, HandleSelectDataItemClick(item, selected)));
                    builder.AddEventStopPropagationAttribute(105, "onclick", true);

                    builder.CloseElement();                     // input
                }
            });
        }