protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            // If this is the first time we've finished rendering, then all the columns
            // have been added to the table so we'll go and get the data for the first time
            if (firstRender)
            {
                try
                {
                    if (AutoLoad)
                    {
                        await GetDataAsync().ConfigureAwait(true);

                        StateHasChanged();
                    }
                }
                catch (Exception ex)
                {
                    await HandleExceptionAsync(ex).ConfigureAwait(true);
                }
            }

            // focus first editor after edit mode begins
            if (BeginEditEvent.WaitOne(0) && Columns.Count > 0 && EditItem != null)
            {
                // find first editable column
                var key = string.Empty;
                foreach (var column in ActualColumnsToDisplay)
                {
                    var editable = column.Editable;
                    // override with dynamic config?
                    var config = ColumnsConfig?.Find(x => x.Id == column.Id);
                    if (config?.Editable ?? editable)
                    {
                        key = column.Id;
                        break;
                    }
                }
                var row = ItemsToDisplay.IndexOf(EditItem);
                if (key != string.Empty)
                {
                    await JSRuntime.InvokeVoidAsync("panoramicData.selectText", $"{IdEditPrefix}-{row}-{key}", _tableBeforeEditArgs !.SelectionStart, _tableBeforeEditArgs !.SelectionEnd).ConfigureAwait(true);

                    BeginEditEvent.Reset();
                }
            }
        }
        /// <summary>
        /// Begins editing of the given item.
        /// </summary>
        public async Task BeginEditAsync()
        {
            if (AllowEdit && !IsEditing && SelectionMode != TableSelectionMode.None && Selection.Count == 1 && KeyField != null)
            {
                // find item to edit
                var item = ItemsToDisplay.Find(x => KeyField(x).ToString() == Selection[0]);
                if (item != null)
                {
                    // notify and allow for cancel
                    EditItem             = item;
                    _tableBeforeEditArgs = new TableBeforeEditEventArgs <TItem>(EditItem);
                    await InvokeAsync(async() => await BeforeEdit.InvokeAsync(_tableBeforeEditArgs).ConfigureAwait(true)).ConfigureAwait(true);

                    if (!_tableBeforeEditArgs.Cancel)
                    {
                        _editValues.Clear();
                        IsEditing = true;
                        BeginEditEvent.Set();
                        await InvokeAsync(StateHasChanged).ConfigureAwait(true);
                    }
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 protected override void BeginEdit()
 {
     BeginEditEvent?.Invoke(this, EventArgs.Empty);
     base.BeginEdit();
 }
 internal void BeginEdit()
 {
     EditText  = Text;
     IsEditing = true;
     BeginEditEvent.Set();
 }