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

131
Visualizações
jQuery - DataTables - How to get clicked row data - .Net 6 MVC

I've followed various examples but not found a solution yet. I have a MVC Web App, the data tables is loaded within a partial view (which then calls instantiateDataTable). I am adding my JS code to get the clicked row data in the view that called this partial view.

I have tried something like this, but both console.logs are coming back as undefined.

   $('#resultsGrid tbody').on('click', function() {
      var row = $(this).parents('tr')[0];
      //for row data
      //console.log(table.row(row).data().id);
      var data = $('resultsGrid').DataTable().row(this).data();
      console.log(row);
      console.log(data);
   });

See JS Fiddle

https://jsfiddle.net/p2one80j/1/

Any advise on why my code isn't working? TIA

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Use this code instead:

$(document).ready(function() {
    var myTable = $('#resultsGrid').DataTable( {
       
    } ); 
    $('#resultsGrid tbody tr').on('click', function() {
      var data = myTable.row(this).data();
      console.log(data);
   }); 
} );

Output:

["102", "A name", "222 The Street", "A City", "IL", "90210", ""]

["100", "A Name", "123 The Street", "A City", "IL", "90210", ""]

about 4 years ago · Juan Pablo Isaza Relatório
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