/// <summary>
        /// 点击选择复选框时触发此方法
        /// </summary>
        /// <param name="state"></param>
        /// <param name="val"></param>
        protected virtual async Task OnCheck(CheckboxState state, TItem val)
        {
            if (state == CheckboxState.Checked)
            {
                SelectedItems.Add(val);
            }
            else
            {
                SelectedItems.Remove(val);
            }

            if (SelectedRowsChanged.HasDelegate)
            {
                await SelectedRowsChanged.InvokeAsync(SelectedRows);
            }

            if (Items != null && HeaderCheckbox != null)
            {
                var headerCheckboxState = SelectedItems.Count == 0 && Items.Count() > 0
                    ? CheckboxState.UnChecked
                    : (SelectedItems.Count == Items.Count() ? CheckboxState.Checked : CheckboxState.Mixed);
                await HeaderCheckbox.SetState(headerCheckboxState);
            }

            if (SelectedRowsChanged.HasDelegate)
            {
                await SelectedRowsChanged.InvokeAsync(SelectedRows);
            }
        }
        /// <summary>
        /// 点击选择复选框时触发此方法
        /// </summary>
        protected Func <CheckboxState, TItem, Task> OnCheck() => async(state, val) =>
        {
            if (state == CheckboxState.Checked)
            {
                SelectedItems.Add(val);
            }
            else
            {
                SelectedItems.Remove(val);
            }

            if (SelectedRowsChanged.HasDelegate)
            {
                await SelectedRowsChanged.InvokeAsync(SelectedRows);
            }

            if (HeaderCheckbox != null)
            {
                var headerCheckboxState = SelectedItems.Count == 0 && Items.Any()
                    ? CheckboxState.UnChecked
                    : (SelectedItems.Count == Items.Count() ? CheckboxState.Checked : CheckboxState.Mixed);
                await HeaderCheckbox.SetState(headerCheckboxState);
            }

            if (SelectedRowsChanged.HasDelegate)
            {
                await SelectedRowsChanged.InvokeAsync(SelectedRows);
            }

            // https://gitee.com/LongbowEnterprise/BootstrapBlazor/issues/I1UYQG
            StateHasChanged();
        };
Beispiel #3
0
 private async Task OnSelectedRowsChanged()
 {
     if (SelectedRowsChanged.HasDelegate)
     {
         await SelectedRowsChanged.InvokeAsync(SelectedRows);
     }
 }
Beispiel #4
0
        void ITable.OnSelectionChanged(int[] checkedIndex)
        {
            var list = new List <TItem>();

            foreach (var index in checkedIndex)
            {
                list.Add(DataSource.ElementAt(index));
            }

            SelectedRows = list.ToArray();
            SelectedRowsChanged.InvokeAsync(SelectedRows);
        }
Beispiel #5
0
 protected void ChangeRowStatus(Status status, object row)
 {
     RequireRender = true;
     chkAll.MarkAsRequireRender();
     if (status == Status.Checked)
     {
         SelectedRows.Add(row);
     }
     else
     {
         SelectedRows.Remove(row);
     }
     if (SelectedRowsChanged.HasDelegate)
     {
         _ = SelectedRowsChanged.InvokeAsync(SelectedRows);
     }
     ResetSelectAllStatus();
 }
Beispiel #6
0
        protected void ChangeAllStatus(Status status)
        {
            RequireRender = true;
            if (status == Status.Checked)
            {
                SelectedRows = new HashSet <object>(rows);
            }
            else
            {
                SelectedRows = new HashSet <object>();
            }

            foreach (var item in rowCheckBoxses.Keys)
            {
                item.MarkAsRequireRender();
            }
            if (SelectedRowsChanged.HasDelegate)
            {
                _ = SelectedRowsChanged.InvokeAsync(SelectedRows);
            }
            ResetSelectAllStatus();
        }
        /// <summary>
        /// 点击 Header 选择复选框时触发此方法
        /// </summary>
        /// <param name="state"></param>
        /// <param name="val"></param>
        protected virtual Task OnHeaderCheck(CheckboxState state, TItem val)
        {
            if (Items != null)
            {
                switch (state)
                {
                case CheckboxState.Checked:
                    // select all
                    SelectedItems.Clear();
                    SelectedItems.AddRange(Items);

                    // callback
                    if (SelectedRowsChanged.HasDelegate)
                    {
                        SelectedRowsChanged.InvokeAsync(SelectedRows);
                    }

                    StateHasChanged();
                    break;

                case CheckboxState.UnChecked:
                    // unselect all
                    SelectedItems.Clear();

                    // callback
                    if (SelectedRowsChanged.HasDelegate)
                    {
                        SelectedRowsChanged.InvokeAsync(SelectedRows);
                    }

                    StateHasChanged();
                    break;

                default:
                    break;
                }
            }
            return(Task.CompletedTask);
        }