<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<table class="example display">
<thead>
<tr>
<th>ID</th>
<th>
Date
</th>
<th>
Client Name
</th>
<th>
Event Type
</th>
<th>
Task owner
</th>
<th>
Options
</th>
</tr>
</thead>
<tfoot>
<tr>
<th>ID
</th>
<th>
Date
</th>
<th>
Client Name
</th>
<th>
Event Type
</th>
<th>
Task owner
</th>
<th>
Options
</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>
126
</td>
<td>
06.03.2016
</td>
<td>
company1
</td>
<td>
PROPOSALS ACCEPTED
</td>
<td>
john
</td>
<td>
<button type="button" data-id="126" class="editView">Edit</button>
<button type="button" data-id="126" class="deleteView">Delete</button>
</td>
</tr>
<tr>
<td>
127
</td>
<td>
04.03.2016
</td>
<td>
Sonex
</td>
<td>
PROPOSALS ACCEPTED
</td>
<td>
bill
</td>
<td>
<button type="button" data-id="127" class="editView">Edit</button>
<button type="button" data-id="127" class="deleteView">Delete</button>
</td>
</tr>
<tr>
<td>
128
</td>
<td>
09.03.2016
</td>
<td>
company1
</td>
<td>
PROPOSALS MADE
</td>
<td>
Greg
</td>
<td>
<button type="button" data-id="128" class="editView">Edit</button>
<button type="button" data-id="128" class="deleteView">Delete</button>
</td>
</tr>
<tr>
<td>
134
</td>
<td>
02.03.2016
</td>
<td>
company1
</td>
<td>
PROPOSALS ACCEPTED
</td>
<td>
Nick
</td>
<td>
<button type="button" data-id="134" class="editView">Edit</button>
<button type="button" data-id="134" class="deleteView">Delete</button>
</td>
</tr>
<tr>
<td>
135
</td>
<td>
04.03.2016
</td>
<td>
company1
</td>
<td>
PROSPECTS VISITS
</td>
<td>
Steve
</td>
<td>
<button type="button" data-id="135" class="editView">Edit</button>
<button type="button" data-id="135" class="deleteView">Delete</button>
</td>
</tr>
<tr>
<td>
136
</td>
<td>
13.03.2016
</td>
<td>
company12
</td>
<td>
PROPOSALS ACCEPTED
</td>
<td>
john
</td>
<td>
<button type="button" data-id="136" class="editView">Edit</button>
<button type="button" data-id="136" class="deleteView">Delete</button>
</td>
</tr>
<tr>
<td>
137
</td>
<td>
04.03.2016
</td>
<td>
company123
</td>
<td>
PROSPECTS VISITS
</td>
<td>
Marck
</td>
<td>
<button type="button" data-id="137" class="editView">Edit</button>
<button type="button" data-id="137" class="deleteView">Delete</button>
</td>
</tr>
</tbody>
</table>
</body>
</html>
<script>
function createCookie(name, value, days) {
var expires;
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
} else {
expires = "";
}
document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/";
}
function readCookie(name) {
var nameEQ = encodeURIComponent(name) + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
}
return null;
}
function eraseCookie(name) {
createCookie(name, "", -1);
}
$.fn.dataTable.ext.search.push(
function (settings, data, dataIndex) {
var minDate = $('#datepicker10').val();
var maxDate = $('#datepicker11').val();
var ageInputs = data[1].split('.');
var age = new Date(ageInputs[2], ageInputs[1] - 1, ageInputs[0]);
//var getdate = date.getDate();
var min;
if (minDate.indexOf(".") > -1) {
var input = minDate.split('.');
var count = input.length;
if (count > 2) {
min = new Date(input[2], input[1] - 1, input[0]);
}
}
var max = new Date(maxDate.split('.')[2], maxDate.split('.')[1] - 1, maxDate.split('.')[0]);
if ((isNaN(min) && isNaN(max)) ||
(isNaN(min) && age <= max) ||
(min <= age && isNaN(max)) ||
(min <= age && age <= max)) {
return true;
}
return false;
}
);
$(document).ready(function () {
//$('.example tfoot th').each(function () {
// var title = $(this).text();
// $(this).html('<input type="text" placeholder="...Filter by column..." />');
//});
//var a1 = readCookie('position');
//window.scrollTo(0, a1);
//if (a1 != null) {
// window.scrollTo(0, a1);
// eraseCookie('position');
//}
//$('.example').DataTable().columnFilter({
// aoColumns: [
// { type: "checkbox", values: ['Gecko', 'Trident'] }, {}, {}, {}, { type: "checkbox", values: ['A', 'C'] }]
//});
var editID;
var t = $('.example').DataTable({
autoFill: true,
colReorder: true,
"iDisplayLength": 1000,
//"sPaginationType": "full_numbers",
//"bStateSave": true,
//"sDom": 'RfrtlipH',
"columnDefs": [
{
"targets": [ 0 ],
"visible": false,
searchable: false
}
],
dom: 'Bfrtip',
buttons: [
{
extend: 'copyHtml5',
exportOptions: {
columns: [0, ':visible']
}
},
{
extend: 'excelHtml5',
exportOptions: {
columns: ':visible'
}
},
{
extend: 'pdfHtml5',
exportOptions: {
columns: [0, 1, 2, 5]
}
},
'colvis'
],
initComplete: function () {
this.api().columns().every(function () {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo($(column.footer()).empty())
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
column.data().unique().sort().each(function (d, j) {
select.append('<option value="' + d + '">' + d + '</option>')
});
});
}
});
$('<a class="dt-button buttons-collection" data-toggle="modal" data-target="#createViewModal"><span>Create</span></a>').appendTo('div.dt-buttons');
$('#datepicker10,#datepicker11,#datepickerCreateModal,#datepickerEditModal').datepicker({
format: 'dd.mm.yyyy'
});
//$('#datepicker10,#datepicker11,#datepickerCreateModal,#datepickerEditModal').on('change', function () {
// $('.datepicker').hide();
//});
//ovo onemogucava manuelni unos putem tastature
jQuery('#datepicker10, #datepicker11').bind('keypress', function (e) {
e.preventDefault();
});
$('#datepicker10, #datepicker11').focusout(function () {
t.draw();
});
$('#datepicker10, #datepicker11').click(function () {
t.draw();
});
$('.example tbody').on('click', 'tr', function () {
if ($(this).hasClass('selected')) {
//$(this).removeClass('selected'); //zakomentarsi
} else {
t.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
});
$('.createView').click(function () {
$.ajax({
url: "/AdeccoViews/CreateAdeccoView",
contentType: 'application/json;',
data: JSON.stringify({ date: document.getElementById('datepickerCreateModal').value, client: $('#client1 :selected').val(), eventtype: $('#eventtype1 :selected').val() }),
//data: JSON.stringify({ id: t.row('.selected').data()[0] }),//pravi kod
type: 'POST',
success:
function (result) {
if (result.id > 0) {
t.row.add([
result.id,
document.getElementById('datepickerCreateModal').value,
$('#client1 :selected').text(),
$('#eventtype1 :selected').text(),
result.name,
'!New'
//formdata = "<button> DeleteSTE </button>"
]).draw(false);
}
$('#modalCreate').modal('toggle');
swal("Dodato!", "Novi je dodat!", "success");
},
error: function (valid) {
//window.location.href = "/Views/ERROR";
swal("Došlo je do greške!", "Molimo vas da pokušate ponovo!", "error");
}
});
});
$('.editView').click(function () {
var ID = $(this).data('id');
//var top = document.getElementById(ID).val();
var top = $(this).position().top;
//alert();
createCookie('position', top, 1);
editID = ID;
$.ajax({
url: "/AdeccoViews/GetDataFromDb",
contentType: 'application/json;',
data: JSON.stringify({ id: ID }),
type: 'POST',
success: function (result) {
if (result.id > 0) {
$("#datepickerEditModal").val(result.date);//iz modala
$("#Client").val(result.client);//iz modala
$("#Eventtype").val(result.eventtype); //#Eventtype iz modala
$('#modalEdit').modal('toggle');
}
},
error: function (valid) {
//window.location.href = "/Views/ERROR";
swal("Došlo je do greške!", "Molimo vas da pokušate ponovo!", "error");
}
});
});
$('.EditModal').click(function() {
$.ajax({
url: "/AdeccoViews/EditModal",
contentType: 'application/json;',
data: JSON.stringify({ id: editID, date: $("#datepickerEditModal").val(), client: $("#Client").val(), eventtype: $("#Eventtype").val() }),
type: 'POST',
success: function (result) {
$('#modalEdit').modal('toggle');
//t.ajax.reload();
//swal("Uspešna izmena", "Šešelj za predsednika!", "success");
swal({
title: "Uspešna izmena",
text:"Uspešno ste izmenili stavku.",
type: "success",
//showCancelButton: true,
confirmButtonClass: 'btn-success',
confirmButtonText: 'OK',
//cancelButtonText: "Odustani",
closeOnConfirm: true,
//closeOnCancel: false
},
function (isConfirm) {
if (isConfirm) {
window.location.href = "/AdeccoViews/Index";
}
});
},
error: function (valid) {
//window.location.href = "/Views/ERROR";
swal("Došlo je do greške!", "Molimo vas da pokušate ponovo!", "error");
}
});
});
$('.deleteView').click(function () {
var ID = $(this).data('id');
swal({
title: "Da li ste sigurni?",
text: "Posle brisanja se ne mogu povratiti podaci.",
type: "warning",
showCancelButton: true,
confirmButtonClass: 'btn-warning',
confirmButtonText: 'Da, obriši',
cancelButtonText: "Odustani",
closeOnConfirm: false,
closeOnCancel: false
},
function (isConfirm) {
if (isConfirm) {
if (t.row('.selected')[0].length == 0) {
swal("Morate selektovati red u tabeli.", "Pokušajte ponovo.", "warning");
return false;
}
$.ajax({
url: "/AdeccoViews/Delete",
contentType: 'application/json;',
data: JSON.stringify({ id: ID }),
//data: JSON.stringify({ id: t.row('.selected').data()[0] }),//pravi kod
type: 'POST',
success: function (result) {
if (result.boolResponse == true) {
t.row('.selected').remove().draw(false);
// if this js function does anything useful (like deleting the row), then call it:
//
swal("Obrisano!", "Veza između korisnika je obrisana!", "success");
}
},
error: function (valid) {
//window.location.href = "/Views/ERROR";
swal("Item has entrance!", "This Item is connected to another table, please remove first all other inputs!", "error");
}
});
} else {
swal("Canceled", "Item is still present.", "info");
}
});
t.fnDraw();
});
});
</script>
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
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 + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
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. |