Disable Left Mouse Click on Editor Template in Telerik Editit: Incell Mode

1 Answer 80 Views
Editor Grid
ACV IT
Top achievements
Rank 1
ACV IT asked on 07 Mar 2023, 03:47 PM

Hi, 

I have a question.  I had a grid which EditMode is Incell and a column had "Editor Template". In this column - "Email", I tried to edit a cell by clicking both left and right mouse, and both of it worked at same way. I used Grid State to edit cell by right mouse clicking.

The problem is: I want to disable edit mode by left click, the cell will edit if it was clicked by right mouse only. 

Many thanks.

    <TelerikGrid Data="@ListUser"
                 ColumnVirtualization="true"
                 Width="100%"
                 Height="inherit"
                 Sortable="true"
                 Resizable="true"
                 OnCancel="@Rebind"
                 OnDelete="@DeleteItem"
                 EditMode="@GridEditMode.Incell"
                 OnEdit="@EditColumnView"
                 OnUpdate="@UpdateHandler"
                 FilterMode="@GridFilterMode.FilterRow"
                     @ref="@GridRef">

        <GridColumns>
                <GridColumn Field="@(nameof(VwModiFyUser.Email))" Editable="@edit_Permission" Title="Email" Width="21%" >
                    <Template>
                        @{
                        VwModiFyUser item = context as VwModiFyUser;

                            <div @oncontextmenu:preventDefault="true" @oncontextmenu="@(()=>{CurrentUser_Name = context as VwModiFyUserEdit_Email2(CurrentUser_Name.RoleuserId);})"> @((context as VwModiFyUser).Email) </div>
                        }
                    </Template>
                    <EditorTemplate>
                        @{
                            VwModiFyUser item = context as VwModiFyUser;                         
                            <TelerikTextBox @bind-Value="item.Email" OnChange="@(()=>Edit_Email(item.RoleuserId))" OnBlur="@CloseEditorAndSave" Width="100%" /> 
                        }
                    </EditorTemplate>

    private async Task Edit_Email(int RoleUserID)

    {
        var currState = GridRef.GetState();
        VwModiFyUser originalItem = List_User.Where(i => i.RoleuserId == RoleIDUserID).FirstOrDefault();
        VwModiFyUser itemToEdit = originalItem;
        currState.EditField = "Email";
        currState.EditItem = itemToEdit;
        currState.OriginalEditItem = originalItem;
        await GridRef.SetStateAsync(currState);
    }                                         

1 Answer, 1 is accepted

Sort by
1
Accepted
Dimo
Telerik team
answered on 09 Mar 2023, 02:13 PM

Hello Tai,

Use @onclick:stopPropagation for the <div> inside the column template. Also, remove the default cell paddings and move them to the <div>, so that users can't click outside the <div>.

Regards,
Dimo
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

ACV IT
Top achievements
Rank 1
commented on 09 Mar 2023, 05:08 PM

Thank you very much. It worked
Tags
Editor Grid
Asked by
ACV IT
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or