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
datatablesinpathslooks contains bunch of anonymous amd modules concatenated together. anonymous module moduledefinecall not set module name. such modules module namerequirecall initiated loading. you cannot concatenate anonymous modules make bundle. callsdefinemust also changed add module name first argumentdefinecall. file may useful people not use module loader, cannot use requirejs.so have setup separate
pathsdatatables,datatables.bootstrap.your
shimdatatablesuseless becausedatatablescallsdefine,shimfiles not calldefine.if want use bootstrap stylings datatables, must load
datatables.bootstrap1 way or another. not that. (even if bundle load fixed work requirejs, you'd have explicitly requestdatatables.bootstrapsomewhere.)datatables.bootstraptry loaddatatables.netratherdatatables. need referdatatablesdatatables.neteverywhere or can usemapbelow.
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