using DataTable() from JS code (without Jquery

using DataTable() from JS code (without Jquery

Dima999Dima999 Posts: 1Questions: 1Answers: 0
edited December 2020 in Free community support

Hi

I need to rewrite method:



(function table() {
$(document).ready(() => {
$('#dataTable').DataTable();
});
}());

without Jquery - only JS:

function docReady(fn) {
if (document.readyState === 'complete' || document.readyState === 'interactive') {
setTimeout(fn, 1);
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
docReady(() => {
document.querySelector('#dataTable').DataTable();
});

And I reductive error -> mainApp.js:42 Uncaught TypeError: Cannot read property 'DataTable' of undefined

How to fix it?

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.