Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda