Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
How do I Prevent Arrow Key Functionality with JavaScript for one element and not the entire program?

Hello I'm working on developing a Data grid within a Blazor Server application. I'm hoping to avoid as much JavaScript as possible (because I'm new to it), but I believe I need JavaScript for this. My datagrid is full of focusable cells(inputs), and the content is being virtualized. I'm needing to stop the scroll functionality with arrow keys on the Datagrid Component. A temporary solution I found was to place this:

window.addEventListener("keydown", function(e) {
    if(["Space","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].indexOf(e.code) > -1) {
        e.preventDefault();
    }
}, false);

inside of the _Host.cshtml page. It works to prevent scrolling with arrow keys.

Here's the rub: I need to only prevent the arrow key event on the one Data grid Component rather than the whole window, because I use arrow keys elsewhere in the application. How can I achieve this?

EDIT

I've tried to reference the grid directly by Id to no avail. Again this code is in the _Host.cshtml and the user navigates through several pages before coming to the Datagrid. There is only one element on the datagrid containing the Id "CustomDataGrid".

var tar = document.GetElementById('CustomDataGrid');
tar.addEventListener("keydown", function (e) {
    if (["Space", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].indexOf(e.code) > -1) {
        e.preventDefault();
    }
}, false);
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda