<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
    <link href="https://cdn.datatables.net/select/1.4.0/css/select.dataTables.min.css" rel="stylesheet" type="text/css" />
    
    <script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
    <script src="https://cdn.datatables.net/select/1.4.0/js/dataTables.select.min.js"></script>
    <meta charset=utf-8 />
    <title>DataTables - JS Bin</title>
  </head>
  <body>
    <div class="container">
      <span> Table 1 </span>
      <table id="table_1" class="display nowrap" width="100%">
        <thead>
          <tr>
            <th>ID</th>
            <th>status</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>1</td>
            <td>B</td>
          </tr>
          <tr>
            <td>2</td>
            <td>B</td>
          </tr>
          <tr>
            <td>3</td>
            <td>C</td>
          </tr>
          <tr>
            <td>4</td>
            <td>D</td>
          </tr>
          <tr>
            <td>5</td>
            <td>E</td>
          </tr>          
        </tbody>
      </table>
    </div>
    <div class="container">
      <span> Table 2 </span>
      <table id="table_2" class="display nowrap" width="100%">
        <thead>
          <tr>
            <th>ID</th>
            <th>status</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>1</td>
            <td>A</td>
          </tr>
          <tr>
            <td>2</td>
            <td>B</td>
          </tr>
          <tr>
            <td>3</td>
            <td>C</td>
          </tr>
          <tr>
            <td>4</td>
            <td>D</td>
          </tr>
          <tr>
            <td>5</td>
            <td>E</td>
          </tr>          
        </tbody>
      </table>
    </div>    
  </body>
</html>
 
body {
  font: 90%/1.45em "Helvetica Neue", HelveticaNeue, Verdana, Arial, Helvetica, sans-serif;
  margin: 0;
  padding: 0;
  color: #333;
  background-color: #fff;
}
 
$(document).ready( function () {
  
  var table_1 = $('#table_1').DataTable({
    dom: "t",
    pageLength: -1,
    select: {
        style: 'os'
    },        
  });
  
  var table_2 = $('#table_2').DataTable({
    dom: "t",
    pageLength: -1,
    select: {
        style: 'os'
    },        
  });  
  
  function doIt(from, to, current) {    
    if (user != current) {
      return;
    }
    
    let status = from.rows({selected:true}).data().pluck(1).toArray();
    
    to.rows().select(false);
    
    to.rows(function(idx, data) {
      return status.includes(data[1]);
    }).select(true);    
    
    setTimeout(function() {
      user = 0;
    }, 100);
  }
  
  // user determines if user clicked, or API
  let user = 0;
  
  table_1.on('select deselect', function() {
      doIt(table_1, table_2, 1);
  })
    
  table_2.on('select deselect', function() {
      doIt(table_2, table_1, 2);
  })
  
  table_1.on( 'user-select', function ( e, dt, type, cell, originalEvent ) {
    user = 1;
  });
  table_2.on( 'user-select', function ( e, dt, type, cell, originalEvent ) {
    user = 2;
  });  
  
      
});
2 errors 2 warnings
Line 24: 'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).
Line 38: 'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).
Line 42: Missing semicolon.
Line 46: Missing semicolon.
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers