2

I just created a web app in Angular 4 with the Angular CLI utility.

I want to display in one page of my web app one table with DatatableJs. I got it, but the style is horrible.

This my result

I think it's due to a dependency installation problem. I installed Bootstrap 4 and DataTables core via npm.

This my configuration in .angular-cli.json file:

enter image description here

Thanks.

2 Answers 2

5

To use Bootstrap 4 with DataTablejs use npm to install Bootstrap 4 package.

npm install --save datatables.net-bs4

Then, Update ".angular-cli.json" files Styles and scripts properties as below.

{
 ........
  "apps": [
    { 
      "styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.min.css",
        //for bootstrap4
        "../node_modules/datatables.net-bs4/css/dataTables.bootstrap4.css"
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.min.js",
        "../node_modules/bootstrap/dist/js/bootstrap.min.js",
        "../node_modules/datatables.net/js/jquery.dataTables.js",
        //for bootstrap4
        "../node_modules/datatables.net-bs4/js/dataTables.bootstrap4.js"
      ]
      ...
    }
  ],
 .....
}

after above changes, we can use bootstrap4 classes to shows table like a bootstrap4 table for example

<table id='table' datatable [dtOptions]="dtOptions" class="table table-striped table-bordered" cellspacing="0" width="100%">
      </table>
Sign up to request clarification or add additional context in comments.

Comments

1

You need the datatables bootstrap4 css.

https://cdn.datatables.net/1.10.15/css/dataTables.bootstrap4.min.css

4 Comments

I put this in my index.html but still not work. <link rel="stylesheet" href="cdn.datatables.net/1.10.15/css/…>
remove dataTables.bootstrap.css from the angular-cli.json and recompile the resources, you probably have a conflict with both on the page
also, this is the link for bootstrap4 css that is used by datatables in their examples. //cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.css
Ok..i have these two references in my index <link rel="stylesheet" href="cdn.datatables.net/1.10.15/css/…> <link rel="stylesheet" href="cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alp‌​ha.6/css/bootstrap.c‌​ss"/> But not work.:( I also removed dataTables.bootstrap.css from config file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.