<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/buttons/css/buttons.dataTables.css?_=c6b24f8a56e04fcee6105a02f4027462.css" rel="stylesheet" type="text/css" />
<script src="https://nightly.datatables.net/buttons/js/dataTables.buttons.js?_=c6b24f8a56e04fcee6105a02f4027462"></script>
<link href="https://nightly.datatables.net/select/css/select.dataTables.css?_=9a6592f8d74f8f520ff7b22342fa1183.css" rel="stylesheet" type="text/css" />
<script src="https://nightly.datatables.net/select/js/dataTables.select.js?_=9a6592f8d74f8f520ff7b22342fa1183"></script>
<link href="https://nightly.datatables.net/datetime/css/dataTables.dateTime.css?_=51ef39aba7fb7ecb2ccd3a91f1dccc6e.css" rel="stylesheet" type="text/css" />
<script src="https://nightly.datatables.net/datetime/js/dataTables.dateTime.js?_=51ef39aba7fb7ecb2ccd3a91f1dccc6e"></script>
<link href="https://editor.datatables.net/extensions/Editor/css/editor.dataTables.min.css" rel="stylesheet" type="text/css" />
<script src="https://editor.datatables.net/extensions/Editor/js/dataTables.editor.min.js"></script>
<meta charset=utf-8 />
<title>DataTables - JS Bin</title>
</head>
<body>
<div class="container">
<h1 aling="center">
Chinese <span>vocabulary</span>
</h1>
<div id="vocabulary_wrapper" class="dataTables_wrapper no-footer">
<div class="dt-buttons">
<button class="dt-button buttons-create" tabindex="0" aria-controls="vocabulary" type="button"><span>New</span></button> <button class="dt-button buttons-selected buttons-edit disabled" tabindex="0" aria-controls="vocabulary" type="button" disabled=""><span>Edit</span></button> <button class="dt-button buttons-selected buttons-remove disabled" tabindex="0" aria-controls="vocabulary" type="button" disabled=""><span>Delete</span></button> <button class="dt-button buttons-csv buttons-html5 btn-space" tabindex="0" aria-controls="vocabulary" type="button"><span>Export CSV</span></button> <button class="dt-button" tabindex="0" aria-controls="vocabulary" type="button"><span>Copy</span></button> <button class="dt-button" tabindex="0" aria-controls="vocabulary" type="button"><span>Import CSV</span></button> <button class="dt-button buttons-select-all btn-space" tabindex="0" aria-controls="vocabulary" type="button"><span>Select all</span></button> <button class="dt-button buttons-select-none disabled" tabindex="0" aria-controls="vocabulary" type="button" disabled=""><span>Deselect all</span></button> </div><div id="vocabulary_filter" class="dataTables_filter"><label>Search:<input type="search" class="" placeholder="" aria-controls="vocabulary"></label></div><table class="display dataTable no-footer" id="vocabulary" aria-describedby="vocabulary_info" style="width: 100%;" width="100%" cellspacing="0" cellpadding="0" border="0">
<thead>
<tr>
<th class="select-checkbox sorting_disabled" rowspan="1" colspan="1" style="width: 11px;" aria-label=""></th><th class="sorting sorting_asc" tabindex="0" aria-controls="vocabulary" rowspan="1" colspan="1" style="width: 57px;" aria-label="A/A: activate to sort column descending" aria-sort="ascending">A/A</th><th class="sorting" tabindex="0" aria-controls="vocabulary" rowspan="1" colspan="1" style="width: 116px;" aria-label="ideogram: activate to sort column ascending">ideogram</th><th class="sorting" tabindex="0" aria-controls="vocabulary" rowspan="1" colspan="1" style="width: 163px;" aria-label="pinyin: activate to sort column ascending">pinyin</th><th class="sorting" tabindex="0" aria-controls="vocabulary" rowspan="1" colspan="1" style="width: 103px;" aria-label="type: activate to sort column ascending">type</th><th class="sorting" tabindex="0" aria-controls="vocabulary" rowspan="1" colspan="1" style="width: 463px;" aria-label="meaning: activate to sort column ascending">meaning</th></tr>
</thead>
<tbody>
<tr id="row_1329" class="odd"><td class=" select-checkbox"></td>
<td class="sorting_1">1329</td><td>叫</td><td>jiào</td><td>Ρ</td><td>ονομάζομαι, φωνάζω</td>
</tr><tr id="row_1330" class="even"><td class=" select-checkbox"></td><td class="sorting_1">1330</td><td>是</td><td>shì</td><td>Ρ</td><td>είμαι</td></tr>
<tr id="row_1331" class="odd"><td class=" select-checkbox"></td><td class="sorting_1">1331</td><td>人</td><td>rén</td><td>ΟΥΣ</td><td>άνθρωπος</td></tr>
<tr id="row_1332" class="even"><td class=" select-checkbox"></td><td class="sorting_1">1332</td><td>不</td><td>bù (bú)</td><td>ΕΠΙΡ</td><td>όχι, δεν</td></tr>
<tr id="row_1333" class="odd"><td class=" select-checkbox"></td><td class="sorting_1">1333</td><td>很</td><td>hěn</td><td>ΕΠΙΡ</td><td>πολύ</td></tr>
<tr id="row_1334" class="even"><td class=" select-checkbox"></td><td class="sorting_1">1334</td><td>好</td><td>hǎo</td><td>ΕΠΙΘ</td><td>καλός/η/ο</td></tr>
<tr id="row_1335" class="odd"><td class=" select-checkbox"></td><td class="sorting_1">1335</td><td>吗</td><td>ma</td><td>Μ</td><td>ερωτηματικό μόριο</td></tr>
<tr id="row_1336" class="even"><td class=" select-checkbox"></td><td class="sorting_1">1336</td><td>饿</td><td> è</td><td>Ρ</td><td>πεινάω</td></tr>
<tr id="row_1337" class="odd"><td class=" select-checkbox"></td><td class="sorting_1">1337</td><td>渴</td><td> kě</td><td>Ρ</td><td>διψάω</td></tr>
<tr id="row_1338" class="even"><td class=" select-checkbox"></td><td class="sorting_1">1338</td><td>喜欢</td><td>xǐhuan</td><td>Ρ</td><td>(μου) αρέσει</td></tr>
</tbody>
</table><div class="dataTables_info" id="vocabulary_info" role="status" aria-live="polite">Showing 1 to 10 of 456 entries</div><div class="dataTables_paginate paging_simple_numbers" id="vocabulary_paginate"><a class="paginate_button previous disabled" aria-controls="vocabulary" data-dt-idx="previous" tabindex="-1" id="vocabulary_previous">Previous</a><span><a class="paginate_button current" aria-controls="vocabulary" data-dt-idx="0" tabindex="0">1</a><a class="paginate_button " aria-controls="vocabulary" data-dt-idx="1" tabindex="0">2</a><a class="paginate_button " aria-controls="vocabulary" data-dt-idx="2" tabindex="0">3</a><a class="paginate_button " aria-controls="vocabulary" data-dt-idx="3" tabindex="0">4</a><a class="paginate_button " aria-controls="vocabulary" data-dt-idx="4" tabindex="0">5</a><span class="ellipsis">…</span><a class="paginate_button " aria-controls="vocabulary" data-dt-idx="45" tabindex="0">46</a></span><a class="paginate_button next" aria-controls="vocabulary" data-dt-idx="next" tabindex="0" id="vocabulary_next">Next</a></div></div>
</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;
}
var editor; // use a global for the submit and return data rendering in the examples
function selectColumns ( editor, csv, header ) {
var selectEditor = new $.fn.dataTable.Editor();
var fields = editor.order();
var toUpdate = []; // array of records to update
var toUpdateIds = []; // array of the IDs of the records to update
var toCreate = []; // array of the records to create
var table = $('#vocabulary').DataTable();
var fieldData;
function parseCSV(PKField) {
var colData = table.column(0).data().toArray();
for (var j =0; j < csv.length; j++){
var get_CSV_ID = csv[j][PKField];
toCreate = colData.filter((number) => {
return number = colData.includes(get_CSV_ID);
});
console.log("2: " + toCreate);
toCreate.push(csv[j]);
}
}
function createRecords() {
if (toCreate.length > 0) {
editor.create(toCreate.length, {
title: 'Confirm import',
buttons: 'Submit',
message: 'Click the <i>Submit</i> button to confirm the import of ' + toCreate.length + ' rows of data. Optionally, override the value for a field to set a common value by clicking on the field below.'
});
for (var i = 0; i < fields.length; i++) {
var field = editor.field(fields[i]);
var mapped = fieldData[field.name()];
for (var j = 0; j < toCreate.length; j++) {
field.multiSet(j, toCreate[j][mapped]);
}
}
}
}
for ( var i=0 ; i<fields.length ; i++ ) {
var field = editor.field( fields[i] );
selectEditor.add( {
label: field.label(),
name: field.name(),
type: 'select',
options: header,
def: header[i]
} );
}
selectEditor.create({
title: 'Map CSV fields',
buttons: 'Import '+csv.length+' records',
message: 'Select the CSV column you want to use the data from for each field.',
onComplete: 'none'
});
selectEditor.on('submitComplete', function(e, json, data, action) {
fieldData = data;
var getID= data[editor.field('id').name()];
parseCSV(getID);
if (toUpdate.length > 0) {
editor.one('submitComplete', function() {
createRecords();
});
} else {
createRecords();
}
});
}
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
ajax: "editor/extension/staff.php",
table: "#vocabulary",
fields: [
{
label: "A/A:",
name: "id"
},
{
label: "Ideogram:",
name: "ideogram"
}, {
label: "pinyin:",
name: "pinyin"
}, {
label: "type:",
name: "type"
}, {
label: "meaning:",
name: "meaning"
}
]
} );
var uploadEditor = new $.fn.dataTable.Editor( {
fields: [ {
label: 'CSV file:',
name: 'csv',
type: 'upload',
ajax: function ( files, done ) {
Papa.parse(files[0], {
header: true,
skipEmptyLines: true,
complete: function (results) {
if ( results.errors.length ) {
console.log( results );
uploadEditor.field('csv').error( 'CSV parsing error: '+ results.errors[0].message );
}
else {
selectColumns( editor, results.data, results.meta.fields );
}
done([0]);
}
});
}
} ]
} );
$('#vocabulary').DataTable( {
dom: "Bfrtip",
order: [[ 1, 'asc' ]],
columns: [
{
data: null,
defaultContent: '',
className: 'select-checkbox',
targets: 0,
orderable: false
},
{ data: "id"},
{ data: "ideogram" },
{ data: "pinyin" },
{ data: "type" },
{ data: "meaning" }
],
select: {
style: 'os',
selector: 'td:first-child'
},
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor },
{
extend: 'csv',
text: 'Export CSV',
className: 'btn-space',
exportOptions: {
orthogonal: null
}
},
{
text: "Copy",
action: function ( e, dt, node, config ) {
var tblData = this.rows('.selected').data();
//console.log(tblData);
var tmpData;
var count=0;
$.each(tblData, function(i, val) {
tmpData = tblData[i];
count = count + 1;
$.post('testing.php', {
data: tmpData
}, function(response) {
//$('#content').html(response);
console.log(response);
});
});
console.log(count);
}
},
{
text: 'Import CSV',
action: function () {
uploadEditor.create( {
title: 'CSV file import'
} );
}
},
{
extend: 'selectAll',
className: 'btn-space'
},
'selectNone',
]
} );
} );
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. |