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

138
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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