This is a migrated thread and some comments may be shown as answers.

Problems with Delete key on grid

1 Answer 51 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ralph
Top achievements
Rank 1
Ralph asked on 05 Mar 2014, 10:14 PM
Hi,
 
My grid has EditMode="Batch"
 <BatchEditingSettings EditType="Row" />

And AllowKeyboardNavigation="true"

Pressing Delete key causes JavaScript errors when no rows are selected.  This happens right after a row was deleted.

I was trying to disable this key through,
       
$(document).keydown(function (e) {
   if (e.which == 46) {
      e.preventDefault();
      return false;
   }
});



This prevents  Delete key from functioning, but only when focus is inside edited textbox. 

When a row is highlighted, the code executes, but a row is deleted anyway.  Setting AllowKeyboardNavigation to false resolves this issue at a loss of other functionality.

Is there a way to disable just the Del key?

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 10 Mar 2014, 11:52 AM
Hello Ralph,

For cross-browser handling of this requirement you will have to use the following approach for canceling the keydown event:
<telerik:RadCodeBlock runat="server">
    <script type="text/javascript">
        function gridKeyDown(event) {
            if (event.keyCode == 46) {
                cancelRawEvent(event);
                event.keyCode = 0; //IE fix
            }
        }
 
        function cancelRawEvent(e) {
            var evt = e ? e : window.event;
            if (evt.stopPropagation) evt.stopPropagation();
            if (evt.preventDefault) evt.preventDefault();
            if (evt.cancelBubble != null) evt.cancelBubble = true;
            if (evt.stopImmediatePropagation) evt.stopImmediatePropagation();
            evt.returnValue = false;
        }
    </script>
</telerik:RadCodeBlock>
 
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" onkeydown="gridKeyDown(event);">
    <MasterTableView EditMode="Batch" BatchEditingSettings-EditType="Row">
    </MasterTableView>
    <ClientSettings AllowKeyboardNavigation="true">
        <Selecting AllowRowSelect="true" />            
    </ClientSettings>
</telerik:RadGrid>

Please give this a try and see if it works as expected on your end.


Regards,
Konstantin Dikov
Telerik

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

Tags
Grid
Asked by
Ralph
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or