Table not rendering using the datatables.bootstrap.css
Hi, I'm able to create a table with angular-datatables but it's not formatted correctly it doesn't seem to be integrating with the datatables.bootstrap.css. I have the following in the <head> of my index.html. The browser is able to load all of the CSS and JS files. I'm using UI Bootstrap.
<link href="/assets/css/bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="/assets/css/datatables.bootstrap.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="/assets/js/vendor/jquery.js"></script>
<script type="text/javascript" src="/assets/js/vendor/jquery.dataTables.js"></script>
<script type="text/javascript" src="/assets/js/vendor/angular.js"></script>
<script type="text/javascript" src="/assets/js/vendor/angular-ui-router.js"></script>
<script type="text/javascript" src="/assets/js/vendor/angular-animate.js"></script>
<script type="text/javascript" src="/assets/js/vendor/ui-bootstrap-tpls.js"></script>
<script type="text/javascript" src="/assets/js/vendor/lodash.js"></script>
<script type="text/javascript" src="/assets/js/vendor/restangular.js"></script>
<script type="text/javascript" src="/assets/js/vendor/angular-datatables.js"></script>
<script type="text/javascript" src="/assets/js/vendor/fastclick.js"></script>
<script type="text/javascript" src="/assets/js/app.js"></script>
<script type="text/javascript" src="/assets/js/controllers/userCtrl.js"></script>
<script type="text/javascript" src="/assets/js/controllers/mainCtrl.js"></script>
<script type="text/javascript" src="/assets/js/controllers/dropDownCtrl.js"></script>
The table I'm trying to render is the Zero Configuration example:
| ID | First name | Last name |
|---|---|---|
| 1 | Foo | Bar |
| 123 | Someone | Youknow |
| 987 | Iamout | Ofinspiration |
Versions of the files I have installed (taken from my bower.json):
"angular-animate": "~1.3.9",
"angular-aside": "~1.1.2",
"angular-bootstrap": "~0.12.0",
"angular-datatables": "~0.3.1",
"angular-highcharts": "*",
"angular-ui-router": "~0.2.13",
"fastclick": "~1.0.3",
"bootstrap": "~3.3.1",
"restangular": "~1.4.0",
"ui-bootstrap": "~0.12.0",
"ui-router": "~0.2.13"
More complete list of version info from bower.json:
"dependencies": { "angular-animate": "~1.3.9", "angular-aside": "~1.1.2", "angular-bootstrap": "~0.12.0", "angular-datatables": "~0.3.1", "angular-highcharts": "*", "angular-ui-router": "~0.2.13", "fastclick": "~1.0.3", "bootstrap": "~3.3.1", "restangular": "~1.4.0", "ui-bootstrap": "~0.12.0", "ui-router": "~0.2.13", "angular": "~1.3.9", "datatables": "~1.10.4", "highcharts.com": "~4.0.4", "jquery": "~2.1.3" }, "resolutions": { "angular": "1.3.9", "highcharts.com": "~v3.0.1" }
Can you provide your JS and HTML code?
JS and HTML code below:
index.html
<!doctype html>
<html lang="en" ng-app="myapp">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>Fabric</title>
<link rel="shortcut icon" type="image/png" href="/assets/img/geek_zombie.png"/>
<link href="/assets/css/bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="/assets/css/datatables.bootstrap.css" rel="stylesheet" type="text/css"/>
<!-- Order is important - jQuery must come before Datatables and Angular so Datatables uses jQuery and not jQueryLite found in Angular -->
<!-- Lodash must load before Restangular -->
<script type="text/javascript" src="/assets/js/vendor/jquery.js"></script>
<script type="text/javascript" src="/assets/js/vendor/jquery.dataTables.js"></script>
<script type="text/javascript" src="/assets/js/vendor/angular.js"></script>
<script type="text/javascript" src="/assets/js/vendor/angular-ui-router.js"></script>
<script type="text/javascript" src="/assets/js/vendor/angular-animate.js"></script>
<script type="text/javascript" src="/assets/js/vendor/ui-bootstrap-tpls.js"></script>
<script type="text/javascript" src="/assets/js/vendor/lodash.js"></script>
<script type="text/javascript" src="/assets/js/vendor/restangular.js"></script>
<script type="text/javascript" src="/assets/js/vendor/angular-datatables.js"></script>
<script type="text/javascript" src="/assets/js/vendor/fastclick.js"></script>
<script type="text/javascript" src="/assets/js/app.js"></script>
<script type="text/javascript" src="/assets/js/controllers/userCtrl.js"></script>
<script type="text/javascript" src="/assets/js/controllers/mainCtrl.js"></script>
<script type="text/javascript" src="/assets/js/controllers/dropDownCtrl.js"></script>
</head>
<body class="ng-cloak" ng-controller="mainCtrl">
<nav class="navbar navbar-default" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" ng-init="navCollapsed = true" ng-click="navCollapsed = !navCollapsed">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="home">myapp</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" ng-class="!navCollapsed && 'in'">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li class="dropdown" dropdown>
<a href="#" ng-controller="dropDownCtrl" dropdown-toggle class="dropdown-toggle" data-toggle="dropdown">Action <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Action</a></li>
<li><a href="#">Action</a></li>
</ul>
</li>
<li class="dropdown" dropdown>
<a href="#" ng-controller="dropDownCtrl" dropdown-toggle class="dropdown-toggle" data-toggle="dropdown">Reference Data <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a ui-sref="users">Action</a></li>
<li><a href="#">Action</a></li>
<li><a href="#">Actions</a></li>
<li><a href="#">Actions</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown" dropdown>
<a href="#" class="dropdown-toggle" dropdown-toggle data-toggle="dropdown">Settings <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<li><a ui-sref="settings">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
<div class="header-placeholder"></div>
<div class="container">
<p>Hello {{name}}!</p>
<table datatable="" class="row-border hover">
<thead>
<tr>
<th>ID</th>
<th>First name</th>
<th>Last name</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Foo</td>
<td>Bar</td>
</tr>
<tr>
<td>123</td>
<td>Someone</td>
<td>Youknow</td>
</tr>
<tr>
<td>987</td>
<td>Iamout</td>
<td>Ofinspiration</td>
</tr>
</tbody>
</table>
<div ui-view></div>
</div>
</body>
</html>
app.js
(function() {
'use strict';
angular.module('myapp', [
'ui.bootstrap',
'ui.router',
'ngAnimate',
//restangular
'restangular',
//angular-datatables
'datatables'
])
.config(config)
.run(run)
;
config.$inject = ['$urlRouterProvider', '$locationProvider', '$stateProvider'];
function config($urlProvider, $locationProvider, $stateProvider) {
$urlProvider.otherwise('/');
$stateProvider
.state('home', {
url: '/',
templateUrl: '/home'
})
.state('users', {
url: '/users',
controller: 'userCtrl',
templateUrl: 'users/users'
})
.state('settings', {
url: 'users/settings',
templateUrl: 'users/settings'
});
$locationProvider.html5Mode({
enabled:false,
requireBase: false
});
$locationProvider.hashPrefix('!');
}
function run() {
FastClick.attach(document.body);
}
})();
mainCtrl.js
angular.module('myapp').controller('mainCtrl', function($scope) {
$scope.name = 'World';
});
dropDownCtrl.js
angular.module('myapp').controller('dropDownCtrl', function($scope) {
$scope.items = [
"The first choice!",
"And another choice for you.",
"but wait! A third!"
];
});
You need to provide at least an option to your table to indicate you want to render your table with Bootstrap.
<body class="ng-cloak" ng-controller="mainCtrl">
...
<table datatable="" dt-options="dtOptions" class="row-border hover">
<thead>
<tr>
<th>ID</th>
<th>First name</th>
<th>Last name</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Foo</td>
<td>Bar</td>
</tr>
<tr>
<td>123</td>
<td>Someone</td>
<td>Youknow</td>
</tr>
<tr>
<td>987</td>
<td>Iamout</td>
<td>Ofinspiration</td>
</tr>
</tbody>
</table>
...
</body>
angular.module('myapp').controller('mainCtrl', function($scope, DTOptionsBuilder) {
$scope.name = 'World';
$scope.dtOptions = DTOptionsBuilder.newOptions().withBootstrap();
});
Thanks, thats improved the formatting but doesn't appear to have rendered all the styling. Sorry is there something else I'm missing?

You forgot the table CSS class in your table:
<table datatable="" dt-options="dtOptions" class="table row-border hover">
...
</table>
For a complete example, see plnkr.
Thanks that worked!
Hi @l-lin I had this same problem and tried many different works around, I also checked your plnkr and in the console, got the same error that I am getting which is:
TypeError: DTOptionsBuilder.newOptions(...).withBootstrap is not a function
It's because the plnkr was using the master version, except that angular-datatables evolved in a way that bootstrap is no longer in the same file as angular-datatables.js.
Here the corrected plnkr.
Awesome!
Hi @l-lin, I'm having same problem. I tried out above both solutions but those didn't worked. got same error TypeError: DTOptionsBuilder.newOptions(...).withBootstrap is not a function. Also I want to remove the filter from data table.
HTML
`
<!-- Favicon -->
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
<link rel="icon" href="images/favicon.ico" type="image/x-icon" />
<!-- CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous" /><!-- load bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" integrity="sha384-aUGj/X2zp5rLCbBxumKTCw2Z50WgIr1vs/PFN4praOTvYXWlVyh2UtNUU0KAUhAX" crossorigin="anonymous" />
<link href='https://fonts.googleapis.com/css?family=Roboto:400,300,900,700,500,100' rel='stylesheet' type='text/css' />
<link rel="stylesheet" href="css/animate.css" type="text/css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" href="css/main.css" type="text/css" />
<link rel="stylesheet" href="css/style.css" type="text/css" />
<!--[if lte IE 9]>
<link href="css/main-ie.css" rel="stylesheet" type="text/css"/>
<link href="css/main-ie-part2.css" rel="stylesheet" type="text/css"/>
<![endif]-->
<link rel="shortcut icon" href="assets/ico/favicon.png">
<!-- SPELLS -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script><!-- load jquery -->
<script src="bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script><!-- load angular -->
<script src="bower_components/angular-datatables/dist/angular-datatables.min.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular-resource.js"></script>
<script src="js/controllers.js"></script>
<script src="js/directives.js"></script>
<script src="js/services.js"></script>
<script src="js/filters.js"></script>
<script src="js/ui-bootstrap-tpls-0.14.3.min.js"></script>
| # | Phone No. | Name | Date of Birth | Address | Photo ID | Actions |
|---|---|---|---|---|---|---|
| {{$index}} | {{ customer_property.phone }} | {{ customer_property.name }} | {{ customer_property.dob | DDMMMYYYY }} | {{ customer_property.address }} | ZBR-{{ customer_property.photoId }} | Delete |
| No Results Found | ||||||
controller `customerDetails.controller('AngularWayWithOptionsCtrl', AngularWayWithOptionsCtrl);
function AngularWayWithOptionsCtrl($resource, DTOptionsBuilder, DTColumnDefBuilder, DTDefaultOptions) { var vm = this; vm.data = []; vm.dtOptions = DTOptionsBuilder.newOptions().withPaginationType('full_numbers').withDisplayLength(2).withBootstrap(); vm.dtColumnDefs = [ DTColumnDefBuilder.newColumnDef(0), // DTColumnDefBuilder.newColumnDef(1).notVisible(), DTColumnDefBuilder.newColumnDef(6).notSortable() ]; $resource('/api/customer_properties').query().$promise.then(function(data) { vm.data = data; }); }`
Don't forget the angular-datatables.bootstrap.js file as well as adding the dependency datatables.bootstrap to your angular app.
Thanks, its working fine now. Can you guide me how to remove the search and show no. of entries from top of the table. See below marked in red.

Use the dom option.
Thanks, its working.
Hi lin. when i am trying to open the above plnkr in Ie, it's throwing error for me. i am using data tables in my application. In chrome its working fine but in IE, search symbol is not displaying as well as text that is typed is also not displaying. is there any property that needs to be added?
hi, Binding Angular directive to the DataTable, I'm trying this but could not able to achieve , can you please send the html and js code. and in my application I need to get data from sql sever database and to be displayed in the datatable. could you please help out to achieve this.
Do you still need the code?
Thanks Sri
On Sunday, March 27, 2016, thanuja143 [email protected] wrote:
hi, Binding Angular directive to the DataTable, I'm trying this but could not able to achieve , can you please send the html and js code. and in my application I need to get data from sql sever database and to be displayed in the datatable. could you please help out to achieve this.
— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/l-lin/angular-datatables/issues/186#issuecomment-202098697
else :
var options = DTOptionsBuilder
.newOptions()
.withOption('serverSide', true)
.withOption('hasBootstrap', true)
.withOption('processing', true)
.withDisplayLength(10)
.withPaginationType('full_numbers')
.withOption('order', [[ 0, 'desc' ]])
.withOption('stateSave', true)
.withOption('searchDelay', 350)
.withOption('width', '100%')
.withDataProp('data');
Hi @l-lin I am also getting TypeError: DTOptionsBuilder.newOptions(...).withBootstrap is not a function
Controller:
'use strict';
angular.module('app').requires.push(['datatables', 'datatables.bootstrap']);
app.controller('myController',
['$scope', 'DTOptionsBuilder', 'DTColumnBuilder',
function ($scope, DTOptionsBuilder, DTColumnBuilder) {
var vm = this;
vm.dtOptions = DTOptionsBuilder.newOptions().withBootstrap();
vm.someData = data;
}
]
);
Without Bootstrap its working but with bootstrap its not.
Configuration for ocLazyLoad:
{
name: 'datatables',
serie: true,
files:[
'https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.12/js/jquery.dataTables.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.12/js/dataTables.bootstrap.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/angular-datatables/0.5.4/plugins/bootstrap/angular-datatables.bootstrap.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/angular-datatables/0.5.4/angular-datatables.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.12/css/dataTables.bootstrap.min.css',
'https://cdnjs.cloudflare.com/ajax/libs/angular-datatables/0.5.4/plugins/bootstrap/datatables.bootstrap.min.css'
]
}
Please tell me what I am doing wrong ???
Console Output:

