0

I'm using DataTables 1.10.4. I'm trying to get the row number of a datatables row I have selected irrespective of the page. I use this:

jQuery(document).on('click', '.someclickedelement', function () 
{ 
    var rowNumber = jQuery(this).parents("tr:first")[0].rowIndex;
});

This gives me the correct row index if my datatable is listing all the rows at once on one page. But if it is listing in pages rowNumber is relative to the current page, not the first page. How do I fix this? How do I get rowIndex relative to the start of the entire table, even if I'm clicking rows on like page 5 or whatever.

1 Answer 1

2

Use the code below:

var table = $('#example').DataTable();   
$('#example').on('click', 'td', function(){
   var index = $('#example').DataTable()
       .rows({ search: 'applied'})
       .nodes()
       .to$()
       .index($(this).closest('tr'));

   alert(index);      
});

See this jsFiddle for code and demonstration.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, that was perfect.
@KenWilliams accept this answer if this is what you needed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.