Skip to content

Instantly share code, notes, and snippets.

@piotr-zuralski
Last active March 18, 2021 14:02
Show Gist options
  • Save piotr-zuralski/8e361dc43c1b05b7973a0e19185b00a1 to your computer and use it in GitHub Desktop.
Save piotr-zuralski/8e361dc43c1b05b7973a0e19185b00a1 to your computer and use it in GitHub Desktop.
Add/Loads DataTable to page - dynamicly
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