Datagrid single tap for editing

1 Answer 86 Views
DataGrid
Andres
Top achievements
Rank 1
Iron
Andres asked on 31 Jul 2024, 09:26 PM

Hi,

Testing the Datagrid, I see that you have to double tap (or click on WIndows) to select a cell for editing.

 

Is there a way for the user to only click the cell once to enter edit mode, or any workaround for this? The current flow is a bit counter intuitive.

 

Thanks

1 Answer, 1 is accepted

Sort by
1
Accepted
Didi
Telerik team
answered on 01 Aug 2024, 08:46 AM

Hi Andres,

By default, the DataGrid enters edit mode on cell double tap. You can modify that behavior by handling CellTap Command and executing the CellDoubleTap default logic instead, here is a quick example:

DataGrid definition:

    <telerik:RadDataGrid x:Name="grid"/>

 

Page's code behind:

public partial class MainPage : ContentPage
{
    public MainPage()
	{
		InitializeComponent();

        var data = new ObservableCollection<Data>();

        for (int i = 0; i < 10; i++)
        {
            data.Add(new Data { Id = i, Name = "Name" + i});
        }

        this.grid.ItemsSource = data;
        this.grid.Commands.Add(new CellTapUserCommand());
    }
}

public class Data
{
    public int Id { get; set; }
    public string Name { get; set; }
}

 

Command:

public class CellTapUserCommand : DataGridCommand
{
    public CellTapUserCommand()
    
        Id = DataGridCommandId.CellTap;
    }
    public override bool CanExecute(object parameter)
    {
        return true;
    }
    public override void Execute(object parameter)
    {
        this.Owner.CommandService.ExecuteDefaultCommand(DataGridCommandId.CellDoubleTap, parameter);
    }
}

In this way, the editing will be triggered as soon as the user clicks/tap on a cell.  In general, the cell updated value should be committed as soon as it exits the edit mode (clicking outside the entry, for example).

Side note: I noticed you open only forum threads. You can also open support tickets if you have a trial or commercial license. Please have this in mind. I can suggest you open support tickets for the questions you have.

Regards,
Didi
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.

Andres
Top achievements
Rank 1
Iron
commented on 02 Aug 2024, 04:30 PM

Hi Didi thanks for your response. I will go ahead and post a ticket, but in the meantime, I tried implementing your solution, however, I can't access my datagrid from code-behind 
 
It gives this error:

As you can see, I'm also using MVVM, so I don't know if that changes things up a bit. Thanks

Lance | Senior Manager Technical Support
Telerik team
commented on 02 Aug 2024, 06:01 PM

Hi Andres, are you sure that you're on the same page as the DataGrid is in XAML? That screenshot shows "BasePage", which is usually not used as a front level page with UI elements in it, so I wanted just to double check this with you and that the MyDataGrid is in fact defined on BasePage.xaml.

An alternative approach to use is to add the command in XAML:

<telerik:RadDataGrid>
    <telerik:RadDataGrid.Commands>
<!-- This being the instance of your custom command type -->
        <local:MyCellTapCommand />
    </telerik:RadDataGrid.Commands>
</telerik:RadDataGrid>

Andres
Top achievements
Rank 1
Iron
commented on 02 Aug 2024, 08:06 PM

Lance,

 

This second approach worked like a breeze, thank you very much.

 

I have one more question, related to datagrid but not this issue, how can I open a support ticket?

 

Thanks

Didi
Telerik team
commented on 05 Aug 2024, 07:22 AM

For opening a ticket, you have to log into your Telerik account. then go to Support Center ->  Contact Us -> Select the Get Technical support. 

Andres
Top achievements
Rank 1
Iron
commented on 05 Aug 2024, 11:49 AM

Thanks for all your help
Tags
DataGrid
Asked by
Andres
Top achievements
Rank 1
Iron
Answers by
Didi
Telerik team
Share this question
or