Jowin / Datatables-Bootstrap3

Plugin for Datatables Bootstrap3 UI Compatibility
215 stars 82 forks source link

Make plugin AMD aware (works perfectly with requirejs and its optimizer now) #15

Closed aaronjwood closed 10 years ago

aaronjwood commented 10 years ago

This plugin previous didn't work with RequireJS when its optimizer is used. It had to do with executing things out of order, even when DataTables was specified to load first and have this plugin be its dependent. Wrapping the plugin with the necessary code to made it AMD aware solves this issue.

coconitro commented 10 years ago

Pointing my bower.json to this branch works flawlessly. Solved a big issue in my project.

Thanks Aaron!

tnguyen14 commented 10 years ago

+1

ddewaele commented 10 years ago

I just started using Grunt / RequireJS / AMD as I came accross this update. Very cool indeed.

Just had a couple of questions. I don't know if I'm doing this right but I added datatables and datatables-bootstrap3 to my bower.json file like this:

{
  "name": "app",
  "version": "0.0.0",
  "dependencies": {
    "jquery": "~1.9.1",
    "datatables": "~1.9.4",
    "datatables-bootstrap3": "git@github:Jowin/Datatables-Bootstrap3.git",
  },
  "devDependencies": {}
}

And then had to modify my RequireJS config to add a shim for datatablesBootstrap3 :

require.config({
    shim: {
        datatablesBootstrap3: {
            deps: ['datatables']
        }        
    },
    paths: {
        datatables: '../bower_components/datatables/media/js/jquery.datatables',
        datatablesBootstrap3: '../bower_components/datatables-bootstrap3/BS3/assets/js/datatables',
    }
});

As far as I understand, this shim config is for "scripts that do not express their dependencies via define()."

Without the shim I got the following runtime error:

Uncaught TypeError: Cannot read property 'defaults' of undefined 

on the following line:

$.extend( true, $.fn.dataTable.defaults, {

I was just wondering , as datatables is a dependency to datatablesBootstrap3, can't we avoid this shim config by having datatablesBootstrap3 "define" its dependency to "datatables" ?

Disclaimer : Like I said ... very new to Grunt / EmberJS and AMD so I hope I'm making sense.