3

我正在创建一个 ngx-datatable,但在表的标题处获得了额外的空间。此外,由于仅此标题,数据行未与标题对齐。这个额外的空间来自表的两端。

我需要删除下图中的标记空间: 数据表

HTML:

<ngx-datatable class='bootstrap' columnMode="force"  [headerHeight]="30" [selectionType]="'multiClick'"
    [rows]="rows">

    <ngx-datatable-column name="UserName"  prop = "UserName" headerClass="mydata-table-header">
    </ngx-datatable-column>

      <ngx-datatable-column name="Date" prop = "Date" headerClass="mydata-table-header" >
      </ngx-datatable-column>
      <ngx-datatable-column name="Activity" prop="Activity" headerClass="mydata-table-header" ></ngx-datatable-column>

      <ngx-datatable-column name="Decision" prop="Activity" headerClass="mydata-table-header" >
      </ngx-datatable-column>
      <ngx-datatable-column name="Remark" prop="Activity" headerClass="mydata-table-header">

      </ngx-datatable-column>

CSS:

.ngx-datatable.bootstrap {
  box-shadow: none;
  font-size: 13px;
  border:none;
  border-collapse: collapse;
}
.ngx-datatable.bootstrap .datatable-header {
  height: unset !important;
  background-color:#28998b;
}
.ngx-datatable.bootstrap .datatable-header .datatable-header-cell {
  vertical-align: bottom;
  padding: 0.75rem;
  border-bottom: 1px solid #000000;
  border-left: 1px solid #000;
  border-right: 1px solid #000;
}
.ngx-datatable.bootstrap .datatable-header .datatable-header-cell .datatable-header-cell-label {
  line-height: 24px;
}
.ngx-datatable.bootstrap .datatable-body {

}
.ngx-datatable.bootstrap .datatable-body .datatable-body-row {
  vertical-align: top;
  border-top: 1px solid #000000;
}
.ngx-datatable.bootstrap .datatable-body .datatable-body-row.datatable-row-even {
  background-color: rgba(0, 0, 0, 0.05);
}
.ngx-datatable.bootstrap .datatable-body .datatable-body-row .datatable-body-cell {
  text-align: left;
  vertical-align: top;
  border-left: 1px solid #000;
  border-right: 1px solid #000;
}
.ngx-datatable.bootstrap .datatable-body .datatable-body-row.active {
  background-color: #1483ff;
  color: #FFF;
}
4

3 回答 3

1

您的 css 文件如下所示:

.datatable-header {
   height: unset !important;
}

.ngx-datatable.bootstrap .datatable-header .datatable-header-cell {
   vertical-align: bottom;
   padding: 0.0rem !important;
   border-bottom: 1px solid #000000;
   border-left: 1px solid #000;
   border-right: 1px solid #000;
   background-color:#28998b;
}

.ngx-datatable.bootstrap .datatable-body .datatable-body-row .datatable-body-cell {
  text-align: left;
  vertical-align: top;
  border-left: 1px solid #000;
  border-right: 1px solid #000;
}

您可能需要调整填充中的值:0.0rem。

还要确保您的自定义 css 是 styleUrls 元数据中的最后一行:

styleUrls: [
   '../../../node_modules/@swimlane/ngx-datatable/release/themes/bootstrap.css',
   './your.component.css'
]
于 2018-03-04T01:37:17.233 回答
0

您可以在 ngx-datatable-column 标记处尝试以下属性:

[width]="150"
[height]="100"
[canAutoResize]="false"

这比使用 css 类更简单,但你仍然可以创建你的 css 类,这取决于你,希望这对有疑问的人有所帮助。

于 2020-10-28T16:59:21.323 回答
0

如果您使用角度(它有效,但它是一种 HACK!):

:host ::ng-deep .ngx-datatable.bootstrap .datatable-header,
:host ::ng-deep .datatable-header {
    height: 30px !important; // set the height of the header
}

:host ::ng-deep .ngx-datatable.bootstrap .datatable-header .datatable-header-cell {
    font-weight: bold;
    padding: 0 0 0 10px !important; // align the header text
}
于 2019-03-21T18:42:10.927 回答