<!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" />
    <script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
       <link href="https://nightly.datatables.net/rowgroup/css/rowGroup.dataTables.min.css" rel="stylesheet" type="text/css" />
    <script src="https://nightly.datatables.net/rowgroup/js/dataTables.rowGroup.min.js"></script>
    <link href="https://nightly.datatables.net/rowreorder/css/rowReorder.dataTables.css?_=6e799325be6f763b41c5c21989f76ec9.css" rel="stylesheet" type="text/css" />
<script src="https://nightly.datatables.net/rowreorder/js/dataTables.rowReorder.js?_=6e799325be6f763b41c5c21989f76ec9"></script>
    <meta charset=utf-8 />
    <title>DataTables - JS Bin</title>
  </head>
  <body>
    <div class="container">
      <table id="example" class="display nowrap" width="100%">
        <thead>
          <tr>
            <th>Ordre</th>
            <th>Categorie</th>
            <th>Commentaire</th>
            <th>Autre</th>
   
          </tr>
        </thead>
    
        <tbody>
            <tr>
                <td>0</td>
                <td>Catégorie 1</td>
                <th>non</th>
                <td>Velo</td>  
            </tr>
            <tr>
                <td>1</td>
                <td>Catégorie 1</td>
                <th>non</th>
                <td>Voiture</td>  
            </tr>
  
            <tr>
                <td>2</td>
                <td>Catégorie 1</td>
                <th>non</th>
                <td>Camion</td>  
            </tr>
            <tr>
                <td>3</td>
                <td>Catégorie 2</td>
                <th>non</th>
                <td>Scooter</td>  
            </tr>
            <tr>
                <td>4</td>
                <td>Catégorie 2</td>
                <th>non</th>
                <td>Moto</td>  
            </tr>
            <tr>
                <td>5</td>
                <td>Catégorie 2</td>
                <th>non</th>
                <td>Fusée</td>  
            </tr>
            
            <tr>
              <td>6</td>
              <td>Catégorie 1</td>
              <th>non</th>
              <td>Avion</td>  
            </tr>
            <tr>
                <td>7</td>
                <td>Catégorie 1</td>
                <th>non</th>
                <td>Bus</td>  
            </tr>
            <tr>
                <td>8</td>
                <td>Catégorie 1</td>
                <th>non</th>
                <td>Skate</td>  
            </tr>
            <tr>
                <td>9</td>
                <td>Catégorie 1</td>
                <th>non</th>
                <td>Voile</td>  
            </tr>
            <tr>
                <td>10</td>
                <td>Catégorie 1</td>
                <th>non</th>
                <td>Train</td>  
            </tr>
            <tr>
                <td>11</td>
                <td>Catégorie 1</td>
                <th>non</th>
                <td>Bateau</td>  
            </tr>
            <tr>
                <td>12</td>
                <td>Catégorie 2</td>
                <th>non</th>
                <td>Mongolfière</td>  
            </tr>
            <tr>
                <td>13</td>
                <td>Catégorie 2</td>
                <th>oui</th>
                <td>Ceci est un commentaire</td>  
             </tr>
            <tr>
                <td>14</td>
                <td>Catégorie 2</td>
                <th>non</th>
                <td>Roller</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 = $('#example').DataTable({
    order: [0,'asc'],
    orderFixed: [1, 'asc'],
    pageLength: 25,
    rowGroup: {
      dataSrc: 1
    },
    rowReorder: true
  });
  
 
  
  //start : Drag-and-drop rowReorder
  table.on('row-reorder', function (e, diff, edit) {
    diff.forEach(function (index) {
        var rowData = table.row(index.node).data();
 
        // Only for commentaire "oui"
        if (rowData[2] === "oui") {
            var targetRowIndex = index.newData;
            var targetRowData = table.row(targetRowIndex).data();
            console.log(targetRowData);
            // Update the categorie
            if (targetRowData[1] !== rowData[1]) {
                rowData[1] = targetRowData[1];
                table.row(index.node).data(rowData).draw();          
            }
        }
    });
  });
  //end : Drag-and-drop rowReorder
  
  
} );
Output

This bin was created anonymously and its free preview time has expired. Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers