简体   繁体   中英

Remove extra empty space from ngx-datatable header

I am creating a ngx-datatable but getting extra space at header of table.Also the data-rows are not aligned to header due to this header only.This extra space is coming at the both end of table.

I need to remove the marked space in the image below: 数据表

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;
}

Your css file would look like:

.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;
}

You could need to adjust the values in padding: 0.0rem.

Also make sure your customised css is the last line in the styleUrls metadata:

styleUrls: [
   '../../../node_modules/@swimlane/ngx-datatable/release/themes/bootstrap.css',
   './your.component.css'
]

If you use angular (it works but it's a kind of 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
}

You can try the following propertyes at the ngx-datatable-column tag:

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

That's simpler than using css classes, but you still can create your css class, up to you, hope this help who's in doubt.

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