Full width home advertisement

OpenCV

HTML

Post Page Advertisement [Top]

In this I am showing how JavaScript can used to manipulate DataTables rows.
See also the post DataTable Image as Table Element

CSS and JS Library to include


 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
 <link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap.min.css">

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
 <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
 <script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap.min.js"></script>

HTML Code


 <button style="margin:15px;"  onclick="fillTable()" > Reload </button>
 <div style="width:90%;margin-top:100px;" class="container">
 <table style="width:100%;" id="userTable_MainId" class="table table-striped table-bordered">
  <thead>
    <tr>
      <th>No.</th>
      <th>Username</th>
      <th>Firstname</th>
      <th>Latname</th> 
      <th>Time</th>
    </tr>
  </thead>
  <tbody id="userTable"> </tbody>
 </table>
 </div>

JavaScript


  function fillTable(){
     var table = $('#userTable_MainId').DataTable();
     table.clear().draw();
     for(var i=0;i<10;i++){
        var d = [i,"User"+i,"Name"+i,"Last Name"+i,new Date().toISOString().slice(11, 19)];
       table.row.add(d).draw( false );    
     }

  }
  
  $(document).ready(function() {
    $('#userTable_MainId').DataTable();
    fillTable();
  });

Demo


No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Colorlib