How to put grid into edit mode for a single cell on the client side

1 Answer 203 Views
Grid
Olga
Top achievements
Rank 1
Iron
Olga asked on 21 Nov 2023, 08:14 PM

Hello,

I have a grid with

EditMode='Batch' 
<BatchEditingSettings EditType="Cell" OpenEditingEvent="DblClick"/>

When I double-click on the cell it (the cell) goes into edit mode which is expected behavior, however I need to achieve the same result by pressing another button located on the same page as grid.

Following code puts entire row into edit mode, but I wonder is there a method to invoke for editing single cell only.

masterTable.editItem(masterTable.get_selectedItems()[0].get_element());
Please advise.

1 Answer, 1 is accepted

Sort by
0
Vasko
Telerik team
answered on 22 Nov 2023, 04:13 PM

Hi Olga,

In order to achieve the desired behavior, I suggest the following approach: 

  • Add the OnClientClicked event to your button: 
    <telerik:RadButton runat="server" ID="RadButton1" Text="Click" AutoPostBack="false" OnClientClicked="onClientClicked"/>
  • In the event handler, open the specific cell of the currently selected row: 
    <script>
        function onClientClicked() {
            var grid = $find("<%= RadGrid1.ClientID %>"); // Replace with your RadGrid's ClientID
            var masterTable = grid.get_masterTableView(); 
            var batchEditingManager = grid.get_batchEditingManager(); 
    
            var selectedRow = masterTable.get_selectedItems()[0]; // Get the currently selected row
    
            if (selectedRow) {
                var cell = selectedRow.get_cell("YourColumnName"); // Replace with your column name
                batchEditingManager.openCellForEdit(cell); // Open the cell
            }
        }
    </script>

Remember to adjust the column name to fit your needs.

Additionally, I suggest taking a look at these articles relevant to the topic:

I hope this helps you out.

Kind regards,
Vasko
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Olga
Top achievements
Rank 1
Iron
commented on 24 Nov 2023, 08:39 PM

Thanks!
Tags
Grid
Asked by
Olga
Top achievements
Rank 1
Iron
Answers by
Vasko
Telerik team
Share this question
or