Datatables and require js conflict?

Datatables and require js conflict?

BDHarrington7BDHarrington7 Posts: 2Questions: 0Answers: 0
edited February 2014 in Bug reports
Hi, I've used Datatables before in a simpler asp.net application, where I could just import the library with a script tag, but I'm working on a different platform now that uses requirejs. It seems like these two plugins aren't playing nice, because I can get both jQuery and datatables.js loaded, but when I call .dataTable() on the jQuery object, the reference to that function can't be found.

Here's a jsfiddle: http://jsfiddle.net/zMqZ3/1/

in my environment, I've paused right inside the callback function for the require call, and verified that datatables was loaded at that point, but the error was still thrown. I haven't been able to find any answers to this on stack overflow or on these forums; there was one guy who seemed to have the same issue, but he didn't give an example and there was no follow-up.

Replies

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    I don't understand why that isn't working I'm afraid. I've just been poking around with it for 15 minutes and don't quite understand why it isn't working - I'll need to come back to it next week (very late here!).

    Allan
  • BDHarrington7BDHarrington7 Posts: 2Questions: 0Answers: 0
    thanks so much for taking a look!
  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    I think because DataTables identifies itself as a named module you need to use something like this:

    [code]
    requirejs.config({
    paths: {
    'datatables': '//cdn.datatables.net/1.10-dev/js/jquery.dataTables'
    }
    });

    require(['datatables'], function () {
    ...
    } );
    [/code]

    http://jsfiddle.net/zMqZ3/8/

    Allan
This discussion has been closed.