javascript - Datatables Bootstrap theme not applying when using ReactJS -
i new requirejs, please gentle!
below link html , js , if run see datatable initialized correctly not applying bootstrap theme.
link problem:
https://jsfiddle.net/sajjansarkar/c2f7s2jz/2/
what doing wrong?
below js (in case fiddle doesnt work):
requirejs.config({ paths: { 'jquery': 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery', 'bootstrap': 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min', 'datatables': 'https://cdn.datatables.net/v/bs/dt-1.10.12/b-1.2.2/b-colvis-1.2.2/b-html5-1.2.2/cr-1.3.2/fh-3.1.2/kt-2.1.3/r-2.1.0/sc-1.4.2/se-1.2.0/datatables.min', }, shim: { 'bootstrap': { deps: ['jquery'] }, 'datatables': ['jquery', 'bootstrap'], } }); require([ 'jquery', 'bootstrap', , 'datatables' ], function($, bootstrap, datatables) { 'use strict'; $('#example').datatable(); });
html:
<head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" /> <link rel="stylesheet" href="https://cdn.datatables.net/1.10.11/css/jquery.datatables.min.css" /> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs/dt-1.10.12/b-1.2.2/b-colvis-1.2.2/b-html5-1.2.2/cr-1.3.2/fh-3.1.2/kt-2.1.3/r-2.1.0/sc-1.4.2/se-1.2.0/datatables.min.css" /> </head> <body> <table id="example" class="table table-striped table-bordered table-hover table-condensed dt-responsive data-table" cellspacing="0" width="100%"> <thead> <tr> <th>name</th> <th>position</th> <th>office</th> <th>age</th> <th>start date</th> <th>salary</th> </tr> </thead> <tbody> <tr> <td>tiger nixon</td> <td>system architect</td> <td>edinburgh</td> <td>61</td> <td>2011/04/25</td> <td>$320,800</td> </tr> ... </tbody></table> </body>
there number of problems trying do:
the file use
datatables
inpaths
looks contains bunch of anonymous amd modules concatenated together. anonymous module moduledefine
call not set module name. such modules module namerequire
call initiated loading. you cannot concatenate anonymous modules make bundle. callsdefine
must also changed add module name first argumentdefine
call. file may useful people not use module loader, cannot use requirejs.so have setup separate
paths
datatables
,datatables.bootstrap
.your
shim
datatables
useless becausedatatables
callsdefine
,shim
files not calldefine
.if want use bootstrap stylings datatables, must load
datatables.bootstrap
1 way or another. not that. (even if bundle load fixed work requirejs, you'd have explicitly requestdatatables.bootstrap
somewhere.)datatables.bootstrap
try loaddatatables.net
ratherdatatables
. need referdatatables
datatables.net
everywhere or can usemap
below.
i proper results if modify javascript this:
requirejs.config({ paths: { 'jquery': 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery', 'bootstrap': 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min', 'datatables': 'https://cdn.datatables.net/1.10.15/js/jquery.datatables.min', 'datatables.bootstrap': 'https://cdn.datatables.net/1.10.15/js/datatables.bootstrap.min', }, shim: { 'bootstrap': { deps: ['jquery'] }, }, map: { '*': { 'datatables.net': 'datatables', } }, }); require(['jquery', 'datatables.bootstrap'], function($) { 'use strict'; $('#example').datatable(); });
here's forked fiddle.
Comments
Post a Comment