JSFiddle - React, Tailwind, and code Playground
by rotailed
HTML
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
<script src="https://cdn.datatables.net/select/1.2.0/js/dataTables.select.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/dataTables.buttons.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/select/1.2.0/css/select.dataTables.css">
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.2.2/css/buttons.dataTables.css">
<link rel="stylesheet" href="https://nightly.datatables.net/css/jquery.dataTables.css">
<div id="result">
</div>
<table id="example" class="table" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
<th>RowNum</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$3,120</td>
<td>1</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Director</td>
<td>Edinburgh</td>
<td>63</td>
<td>2011/07/25</td>
<td>$5,300</td>
<td>2</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
<td>$4,800</td>
<td>3</td>
</tr>
<tr>
<td>Cedric Kelly</td>
<td>Javascript Developer</td>
<td>Edinburgh</td>
<td>22</td>
<td>2012/03/29</td>
<td>$3,600</td>
<td>4</td>
</tr>
<tr>
<td>Jenna Elliott</td>
...
JavaScript
$(document).ready(function() {
var table = $('#example').DataTable( {
dom: 'Bfrtip',
select: true,
buttons: [
{
text: 'Modify selected user age',
action: function ( e, dt, button, config ) {
console.log('ici');
var thisRow = dt.row({ selected: true }).data()[6];
var actualUser = dt.row({ selected: true }).data()[0];
var actualAge = dt.row({ selected: true }).data()[3];
var newAge = Number(actualAge) + 1;
if (confirm('Modify ' + actualUser + ' age\'s to ' + newAge+ ' ?')) {
$("#result").text('Database update : New age for ' + actualUser + ' is ' + newAge);
$('#example').DataTable().cell(':eq(1)', 3).data( newAge );
}
}
}
]
} );
} );