HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div class="alert alert-danger" role="alert"><strong>Info!</strong> Add row and Delete row are working. Edit row displays modal with row cells information.</div>
<a class="btn btn-success" style="float:left;margin-right:20px;" href="https://codepen.io/collection/XKgNLN/" target="_blank">Other examples on Codepen</a>
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Order</th>
<th>Description</th>
<th>Deadline</th>
<th>Status</th>
<th>Amount</th>
<th style="text-align:center;width:100px;">Add row <button type="button" data-func="dt-add" class="btn btn-success btn-xs dt-add">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button></th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Alphabet puzzle</td>
<td>2016/01/15</td>
<td>Done</td>
<td>1000</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>2</td>
<td>Layout for poster</td>
<td>2016/01/31</td>
<td>Planned</td>
<td>1834</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>3</td>
<td>Image creation</td>
<td>2016/01/23</td>
<td>To Do</td>
<td>1500</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>4</td>
<td>Create font</td>
<td>2016/02/26</td>
<td>Done</td>
<td>1200</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>5</td>
<td>Sticker production</td>
<td>2016/02/18</td>
<td>Planned</td>
<td>2100</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>6</td>
<td>Glossy poster</td>
<td>2016/03/17</td>
<td>To Do</td>
<td>899</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>7</td>
<td>Beer label</td>
<td>2016/05/28</td>
<td>Confirmed</td>
<td>2499</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>8</td>
<td>Shop sign</td>
<td>2016/04/19</td>
<td>Offer</td>
<td>1099</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>9</td>
<td>X-Mas decoration</td>
<td>2016/10/31</td>
<td>Confirmed</td>
<td>1750</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>10</td>
<td>Halloween invite</td>
<td>2016/09/12</td>
<td>Planned</td>
<td>400</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>11</td>
<td>Wedding announcement</td>
<td>2016/07/09</td>
<td>To Do</td>
<td>299</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>12</td>
<td>Member pasport</td>
<td>2016/06/22</td>
<td>Offer</td>
<td>149</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>13</td>
<td>Drink tickets</td>
<td>2016/11/01</td>
<td>Confirmed</td>
<td>199</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>14</td>
<td>Album cover</td>
<td>2017/03/15</td>
<td>To Do</td>
<td>4999</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>15</td>
<td>Shipment box</td>
<td>2017/02/08</td>
<td>Offer</td>
<td>1399</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>16</td>
<td>Wooden puzzle</td>
<td>2017/01/11</td>
<td>Done</td>
<td>1000</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>17</td>
<td>Fashion Layout</td>
<td>2016/01/30</td>
<td>Planned</td>
<td>1834</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>18</td>
<td>Toy creation</td>
<td>2016/01/10</td>
<td>To Do</td>
<td>1550</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>19</td>
<td>Create stamps</td>
<td>2016/02/26</td>
<td>Done</td>
<td>1220</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>20</td>
<td>Sticker design</td>
<td>2017/02/18</td>
<td>Planned</td>
<td>2100</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>21</td>
<td>Poster rock concert</td>
<td>2017/04/17</td>
<td>To Do</td>
<td>899</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>22</td>
<td>Wine label</td>
<td>2017/05/28</td>
<td>Confirmed</td>
<td>2799</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>23</td>
<td>Shopping bag</td>
<td>2017/04/19</td>
<td>Offer</td>
<td>1299</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>24</td>
<td>Decoration for Easter</td>
<td>2017/10/31</td>
<td>Confirmed</td>
<td>1650</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>25</td>
<td>Saint Nicolas colorbook</td>
<td>2017/09/12</td>
<td>Planned</td>
<td>510</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>26</td>
<td>Wedding invites</td>
<td>2017/07/09</td>
<td>To Do</td>
<td>399</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>27</td>
<td>Member pasport</td>
<td>2017/06/22</td>
<td>Offer</td>
<td>249</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>28</td>
<td>Drink tickets</td>
<td>2017/11/01</td>
<td>Confirmed</td>
<td>199</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>29</td>
<td>Blue-Ray cover</td>
<td>2018/03/15</td>
<td>To Do</td>
<td>1999</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<tr>
<td>30</td>
<td>TV carton</td>
<td>2019/02/08</td>
<td>Offer</td>
<td>1369</td>
<td>
<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-danger btn-xs dt-delete">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
</tbody>
</table>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Row information</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
body {margin:2em;}
td:last-child {text-align:center;}
$(document).ready(function() {
//Only needed for the filename of export files.
//Normally set in the title tag of your page.
document.title='Simple DataTable';
// DataTable initialisation
$('#example').DataTable(
{
"dom": '<"dt-buttons"Bf><"clear">lirtp',
"paging": false,
"autoWidth": true,
"columnDefs": [
{ "orderable": false, "targets": 5 }
],
"buttons": [
'colvis',
'copyHtml5',
'csvHtml5',
'excelHtml5',
'pdfHtml5',
'print'
]
}
);
//Add row button
$('.dt-add').each(function () {
$(this).on('click', function(evt){
//Create some data and insert it
var rowData = [];
var table = $('#example').DataTable();
//Store next row number in array
var info = table.page.info();
rowData.push(info.recordsTotal+1);
//Some description
rowData.push('New Order');
//Random date
var date1 = new Date(2016,01,01);
var date2 = new Date(2018,12,31);
var rndDate = new Date(+date1 + Math.random() * (date2 - date1));//.toLocaleDateString();
rowData.push(rndDate.getFullYear()+'/'+(rndDate.getMonth()+1)+'/'+rndDate.getDate());
//Status column
rowData.push('NEW');
//Amount column
rowData.push(Math.floor(Math.random() * 2000) + 1);
//Inserting the buttons ???
rowData.push('<button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></button><button type="button" class="btn btn-danger btn-xs dt-delete"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>');
//Looping over columns is possible
//var colCount = table.columns()[0].length;
//for(var i=0; i < colCount; i++){ }
//INSERT THE ROW
table.row.add(rowData).draw( false );
//REMOVE EDIT AND DELETE EVENTS FROM ALL BUTTONS
$('.dt-edit').off('click');
$('.dt-delete').off('click');
//CREATE NEW CLICK EVENTS
$('.dt-edit').each(function () {
$(this).on('click', function(evt){
$this = $(this);
var dtRow = $this.parents('tr');
$('div.modal-body').innerHTML='';
$('div.modal-body').append('Row index: '+dtRow[0].rowIndex+'<br/>');
$('div.modal-body').append('Number of columns: '+dtRow[0].cells.length+'<br/>');
for(var i=0; i < dtRow[0].cells.length; i++){
$('div.modal-body').append('Cell (column, row) '+dtRow[0].cells[i]._DT_CellIndex.column+', '+dtRow[0].cells[i]._DT_CellIndex.row+' => innerHTML : '+dtRow[0].cells[i].innerHTML+'<br/>');
}
$('#myModal').modal('show');
});
});
$('.dt-delete').each(function () {
$(this).on('click', function(evt){
$this = $(this);
var dtRow = $this.parents('tr');
if(confirm("Are you sure to delete this row?")){
var table = $('#example').DataTable();
table.row(dtRow[0].rowIndex-1).remove().draw( false );
}
});
});
});
});
//Edit row buttons
$('.dt-edit').each(function () {
$(this).on('click', function(evt){
$this = $(this);
var dtRow = $this.parents('tr');
$('div.modal-body').innerHTML='';
$('div.modal-body').append('Row index: '+dtRow[0].rowIndex+'<br/>');
$('div.modal-body').append('Number of columns: '+dtRow[0].cells.length+'<br/>');
for(var i=0; i < dtRow[0].cells.length; i++){
$('div.modal-body').append('Cell (column, row) '+dtRow[0].cells[i]._DT_CellIndex.column+', '+dtRow[0].cells[i]._DT_CellIndex.row+' => innerHTML : '+dtRow[0].cells[i].innerHTML+'<br/>');
}
$('#myModal').modal('show');
});
});
//Delete buttons
$('.dt-delete').each(function () {
$(this).on('click', function(evt){
$this = $(this);
var dtRow = $this.parents('tr');
if(confirm("Are you sure to delete this row?")){
var table = $('#example').DataTable();
table.row(dtRow[0].rowIndex-1).remove().draw( false );
}
});
});
$('#myModal').on('hidden.bs.modal', function (evt) {
$('.modal .modal-body').empty();
});
});
Also see: Tab Triggers