General developer forum

Problem with JQuery DataTables in Moodle 3

 
Picture of Ken Currie
Problem with JQuery DataTables in Moodle 3
 

I use the JQuery DataTables library successfully in Moodle 2, but in Moodle 3 I get errors - see below - I think with requiresjs.


Anyone successfully using DataTables?  I am trying to use this library in a module, not theme wide, so that the module would work in any theme.  

Ken Currie


--- Errors --

* Uncaught TypeError: $(...).DataTable is not a function

    at HTMLDocument.<anonymous> (view.php?id=35:116)

    at i (jquery-1.12.1.min.js:2)

    at Object.fireWith [as resolveWith] (jquery-1.12.1.min.js:2)

    at Function.ready (jquery-1.12.1.min.js:2)

    at HTMLDocument.K (jquery-1.12.1.min.js:2)


* Uncaught Error: Mismatched anonymous define() module: function (E){return h(E,window,document)}

http://requirejs.org/docs/errors.html#mismatch

    at B (require.min.js:12)

    at J (require.min.js:27)

    at require.min.js:27

 
Average of ratings: -
Picture of kien Vu
Re: Problem with JQuery DataTables in Moodle 3
Group Plugin developers
You can try this 


It fixed the similar issue for me.

Cheers,

Kien

 
Average of ratings: -
Raymond
Re: Problem with JQuery DataTables in Moodle 3
 

Hi Kien,

You just might solve all my problems with jquery ui if your answer to my question is yes.

If I call this line which you provided above, will i instantly get access to the jquery ui datatables functionality? Without having to write/ build any AMD modules as prescribed in the moodle docs?

$PAGE->requires->js(new moodle_url('https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js'),true);

 
Average of ratings: -