简体   繁体   English

Angular4 CLI项目中的Bootstrap 4 Datatablejs

[英]Bootstrap 4 Datatablejs in Angular4 CLI project

I just created a web app in Angular 4 with the Angular CLI utility. 我刚刚使用Angular CLI实用工具在Angular 4中创建了一个Web应用程序。

I want to display in one page of my web app one table with DatatableJs. 我想在Web应用程序的一页中显示一个带有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. 我通过npm安装了Bootstrap 4和DataTables核心

This my configuration in .angular-cli.json file: 这是我在.angular-cli.json文件中的配置:

在此处输入图片说明

Thanks. 谢谢。

To use Bootstrap 4 with DataTablejs use npm to install Bootstrap 4 package. 要将Bootstrap 4与DataTablejs一起使用,请使用npm安装Bootstrap 4软件包。

npm install --save datatables.net-bs4

Then, Update ".angular-cli.json" files Styles and scripts properties as below. 然后,如下更新“ .angular-cli.json”文件的样式和脚本属性。

{
 ........
  "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 经过上述更改后,我们可以使用bootstrap4类来显示表,例如bootstrap4表

<table id='table' datatable [dtOptions]="dtOptions" class="table table-striped table-bordered" cellspacing="0" width="100%">
      </table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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