Last active
March 18, 2021 14:02
-
-
Save piotr-zuralski/8e361dc43c1b05b7973a0e19185b00a1 to your computer and use it in GitHub Desktop.
Add/Loads DataTable to page - dynamicly
This file contains 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
function __loadScript(url, integrity, callback) { | |
let script = document.createElement("script"); | |
script.crossOrigin = "anonymous" | |
script.src = url | |
if (typeof integrity === "string") { | |
script.integrity = integrity | |
} | |
if (typeof callback === "function") { | |
script.onload = callback | |
} | |
document.head.appendChild(script) | |
} | |
if (typeof jQuery === "undefined") { | |
__loadScript( | |
"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js", | |
"sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" | |
) | |
} | |
function __addDataTable() { | |
let tables = jQuery('table') | |
tables.each(function (index, element) { | |
element = jQuery(element) | |
element.DataTable(); | |
}) | |
} | |
__loadScript( | |
"https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.21/js/jquery.dataTables.min.js", | |
"sha512-BkpSL20WETFylMrcirBahHfSnY++H2O1W+UnEEO4yNIl+jI2+zowyoGJpbtk6bx97fBXf++WJHSSK2MV4ghPcg==", | |
__addDataTable | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment