Created
July 16, 2019 20:10
-
-
Save BonBonSlick/e2b66a762fa9d4694db704cf34a52b50 to your computer and use it in GitHub Desktop.
Very old multiple records removing JQuery script, I do not need it anymore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import Routing from '../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js'; | |
// Routing.setRoutingData(routes); | |
//event triggers | |
$(document).on('change', '.check_all', checkAllRows); | |
$(document).on('click', '#delete_all', deleteSelected); | |
// checks all checkboxes to delete items | |
function checkAllRows() { | |
if ($('.check_all:checked').length > 0) { | |
$('.checker').each(function () { | |
$($(this)).prop('checked', true); | |
}); | |
} else { | |
$('.checker').each(function () { | |
$($(this)).prop('checked', false); | |
}); | |
} | |
} | |
/** | |
* delete selected rows in table | |
*/ | |
function deleteSelected() { | |
let confirmDelete = confirm('Are you sure?'); | |
if (!confirmDelete) { | |
return; | |
} | |
$('.checker').each(function () { | |
let checkedRow = $(this); | |
if (checkedRow.is(':checked')) { | |
let deleteRoute = checkedRow.val(); | |
$.ajax({ | |
url: deleteRoute, | |
beforeSend: function (xhr) { | |
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content')) | |
}, | |
type: 'POST', | |
data: { | |
"_method": 'DELETE', | |
}, | |
success: function () { | |
checkedRow.closest("tr").remove(); | |
}, | |
error: function (response) { | |
console.log(response); | |
} | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment