Completed
Last Updated: 10 Apr 2023 13:57 by ADMIN
Release 4.2.0 (04/26/2023)
Andrew
Created on: 15 Jun 2020 14:49
Category: Grid
Type: Feature Request
17
Allow control over the Popup edit form Buttons at the bottom
I am trying to customize the Update button in the popup to show a different text while I am updating an item. THe same approach works in the Inline mode, but not in Popup.
1 comment
ADMIN
Marin Bratanov
Posted on: 15 Jun 2020 14:51

A workaround is to use a custom popup for editing where you can control all the rendering: https://github.com/telerik/blazor-ui/tree/master/grid/custom-popup-form.

If/when such a feature gets implemented, it will probably be separate settings for the popup - it cannot use the commands defined in the column because it is not in the column. For the time being, texts for those buttons can be set through localization in case creating a custom popup form is not an option for you.

Here is a reproducible that showcases the perceived issue:

 

@using System.ComponentModel.DataAnnotations


@isCurrentlyUpdating
<br />


<TelerikGrid Data=@MyData EditMode="@GridEditMode.Popup" Pageable="true" Height="500px"
             OnUpdate="@UpdateHandler" OnDelete="@DeleteHandler" OnCreate="@CreateHandler" OnCancel="@CancelHandler">
    <GridToolBar>
        <GridCommandButton Command="Add" Icon="add">Add Employee</GridCommandButton>
    </GridToolBar>
    <GridColumns>
        <GridColumn Field=@nameof(SampleData.ID) Title="ID" Editable="false" />
        <GridColumn Field=@nameof(SampleData.Name) Title="Name" />
        <GridCommandColumn>
            <GridCommandButton Command="Save" Icon="save" ShowInEdit="true" Enabled="@( !isCurrentlyUpdating )">
                @if (isCurrentlyUpdating)
                {
                    <text>Please wait...working</text>
                }
                else
                {
                    <text>Do my Update</text>
                }
            </GridCommandButton>
            <GridCommandButton Command="Edit" Icon="edit">Edit</GridCommandButton>
            <GridCommandButton Command="Delete" Icon="delete">Delete</GridCommandButton>
            <GridCommandButton Command="Cancel" Icon="cancel" ShowInEdit="true">Cancel</GridCommandButton>
        </GridCommandColumn>
    </GridColumns>
</TelerikGrid>

@code {
    bool isCurrentlyUpdating { get; set; }
    async Task UpdateHandler(GridCommandEventArgs args)
    {
        isCurrentlyUpdating = true;
        await Task.Delay(2000); // simulate long delay from some async operations
        isCurrentlyUpdating = false;

        SampleData item = (SampleData)args.Item;

        // perform actual data source operations here through your service

        // if the grid Data is not tied to the service, you may need to update the local view data too
        var index = MyData.FindIndex(i => i.ID == item.ID);
        if (index != -1)
        {
            MyData[index] = item;
        }

        Console.WriteLine("Update event is fired.");
    }






    async Task DeleteHandler(GridCommandEventArgs args)
    {
        SampleData item = (SampleData)args.Item;

        // perform actual data source operation here through your service

        // if the grid Data is not tied to the service, you may need to update the local view data too
        MyData.Remove(item);

        Console.WriteLine("Delete event is fired.");
    }

    async Task CreateHandler(GridCommandEventArgs args)
    {
        SampleData item = (SampleData)args.Item;

        // perform actual data source operation here through your service

        // if the grid Data is not tied to the service, you may need to update the local view data too
        item.ID = MyData.Count + 1;
        MyData.Insert(0, item);

        Console.WriteLine("Create event is fired.");
    }

    async Task CancelHandler(GridCommandEventArgs args)
    {
        SampleData item = (SampleData)args.Item;

        // if necessary, perform actual data source operation here through your service

        Console.WriteLine("Cancel event is fired.");
    }


    // in a real case, keep the models in dedicated locations, this is just an easy to copy and see example
    public class SampleData
    {
        public int ID { get; set; }

        [Required(ErrorMessage = "The employee must have a name")]
        public string Name { get; set; }
    }

    public List<SampleData> MyData { get; set; }

    protected override void OnInitialized()
    {
        MyData = new List<SampleData>();

        for (int i = 0; i < 50; i++)
        {
            MyData.Add(new SampleData()
            {
                ID = i,
                Name = "Name " + i.ToString()
            });
        }
    }
}

 

 

Regards,
Marin Bratanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.