javascript - set index to table row -




i have table has 30 rows. wrote below code set number index each row.from 1-to 30 code works good. when variable called : cyrrentpage has 2 content . row number added 1 before index . instead of start 31. should ? here snippet:

var cyrrentpage =2  if(cyrrentpage == 1)  {    $(".row_number").each(function(index, element) {      $(this).text( $(this).closest("tr").index()+1)  });  }  else  {  $(".row_number").each(function(index, element) {                if(index == 50)    {      $(this).text("cyrrentpage 0");            }            else{      $(this).text( (cyrrentpage-1).tostring()+($(this).closest("tr").index()+1).tostring())          }  });  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <table border="1">  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  <tr><td class="row_number">1</td><td> hello</td></tr>  </table>

the line

$(this).text( (cyrrentpage-1).tostring()+($(this).closest("tr").index()+1).tostring()) 

should be

$(this).text(30*(cyrrentpage-1).tostring()+ +($(this).closest("tr").index()+1).tostring()) 

notice unary + converts number.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -