Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!