简体   繁体   中英

Bootstrap 4 Datatablejs in Angular4 CLI project

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.

这是我的结果

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:

在此处输入图片说明

Thanks.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM