<html>
<head>
<meta name="description" content="Toggle-Switch no working on responsive" />
<meta charset="utf-8">
<title>DataTables - JS Bin</title>
<script src="https://code.jquery.com/jquery-3.7.0.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.5/css/jquery.dataTables.css">
<script src="https://cdn.datatables.net/1.13.5/js/jquery.dataTables.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs-3.3.7/dt-1.10.16/datatables.min.css">
<link href="https://cdn.datatables.net/1.13.10/css/dataTables.bootstrap4.css" rel="stylesheet">
<link href="https://cdn.datatables.net/responsive/2.5.0/css/responsive.bootstrap4.css" rel="stylesheet">
<script src="https://cdn.datatables.net/1.13.10/js/jquery.dataTables.js"></script>
<script src="https://cdn.datatables.net/1.13.10/js/dataTables.bootstrap4.js"></script>
<script src="https://cdn.datatables.net/responsive/2.5.0/js/dataTables.responsive.js"></script>
<script src="https://cdn.datatables.net/responsive/2.5.0/js/responsive.bootstrap4.js"></script>
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
<style id="jsbin-css">
body {
font: 90%/1.45em "Helvetica Neue", HelveticaNeue, Verdana, Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
color: #333;
background-color: #fff;
}
</style>
<body>
<div class="container">
<table id="example" class="table table-striped table-bordered table-responsive" width="100%">
<thead>
<tr>
<th>Select</th>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
<th>chk</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Select</th>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
<th>chk</th>
</tr>
</tfoot>
<tbody>
<tr>
<th>1</th>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$3,120</td>
<th>1</th>
</tr>
<tr>
<th>0</th>
<td>Garrett Winters</td>
<td>Director</td>
<td>Edinburgh</td>
<td>63</td>
<td>2011/07/25</td>
<td>$5,300</td>
<th>0</th>
</tr>
<tr>
<th>1</th>
<td>Ashton Cox</td>
<td>Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
<td>$4,800</td>
<th>1</th>
</tr>
<tr>
<th>0</th>
<td>Cedric Kelly</td>
<td>Javascript Developer</td>
<td>Edinburgh</td>
<td>22</td>
<td>2012/03/29</td>
<td>$3,600</td>
<th>1</th>
</tr>
<tr>
<th>1</th>
<td>Jenna Elliott</td>
<td>Financial Controller</td>
<td>Edinburgh</td>
<td>33</td>
<td>2008/11/28</td>
<td>$5,300</td>
<th>0</th>
</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({
pageLength: 10,
responsive: true,
columnDefs: [{
targets: [0],
data: "active",
className: "dt-body-center",
render: function (data, type, row) {return RenderToggle(data, type, row, state=1)}
},
{
targets: [7],
data: "specific",
className: "dt-body-center",
render: function (data, type, row) {return RenderToggle(data, type, row, state=0)}
},
],
order: [[1, 'asc']],
rowCallback: function (row, data) {
$('input.toggle-switch', row).prop('checked', data.active == 1).bootstrapToggle({ size: 'mini' });
}
});
function RenderToggle(data, type, row, state) {
let chk = state == 1 ? "checkbox" : "checkbox-inactive";
if (type === 'display') {
return '<input type= "'+ chk +'" class="toggle-switch" data-on="Yes" data-off="No" data-onstyle="success" data-offstyle="danger" data-style="mr-1" data-size="xs">';
}
return data;
}
});
You can jump to the latest bin by adding /latest
to your URL
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + [ | Indents selected lines |
ctrl + ] | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Clone Bin |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |