如何设置Primeng数据表列自动适合? [英] how set primeng data table columns auto fit?

查看:97
本文介绍了如何设置Primeng数据表列自动适合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使主要的ng数据表列设置为自动适应以及可调整大小.因此,我解决了在两个css类.ui-datatable表和.ui-datatable-tablewrapper中更改的问题.

I have want to make prime ng data table columns set auto fit as well as re sizeable.So I have solved this issue changed in two css class .ui-datatable table and .ui-datatable-tablewrapper.

推荐答案

我使用了以下代码. 在SCSS中更改了table-layout:auto!important; .html

I have used following code. Changed in SCSS set table-layout:auto !important; .html

<p-dataTable [value]="Dataset"  [style]="{'width':'100%','overflow':'auto!important'}" 
      [responsive]="true"  [rows]="20" 
       [resizableColumns]="true" 
       columnResizeMode="expand" 
       [immutable]=false
       [paginator]="true" [rowsPerPageOptions]="[10,15,20,25]"
      appendTo="body" #dt>
      <p-column  styleClass="checkbox ui-resizable-column" [style]="{'width': 'auto'}" selectionMode="multiple">
      </p-column>  
      <p-column *ngFor="let col of cols;let j=index;" [style]="{'width':'auto','display':col.display} " [field]="col.field" [header]="col.header"
        [sortable]="true" [filter]="true" filterPlaceholder="Search" (mouseleave)="hoveredIndex=null" filterPlaceholder="Search"
        appendTo="body">
        <ng-template let-row="rowData" let-i="rowIndex" pTemplate="body">
          <div [pTooltip]="row[col.field]" [id]="col.field"></div>
             <!-- set String  -->
            <span (click)="test(dt)"  style="text-align:left;" *ngIf="col.datatype!='int' && col.datatype!='float'">
              {{row[col.field]}}
            </span>
             <!-- set int  -->
            <span  (click)="test(dt)"  style="text-align:top;float: top;padding-top: 4px !important;" *ngIf="col.datatype=='int' || col.datatype=='float' ">
              {{row[col.field]}}
            </span>
        </ng-template>
      </p-column>
    </p-dataTable> 


.scss


.scss

@import "src/app/Themes/colorVariables";  //datatable ui
    //Updated row
    ::ng-deep .ui-datatable tbody > tr.ng-star-inserted.ui-widget-updated-row{
        background-color:$updated-row-color;
    } 
    ::ng-deep .ui-datatable tbody > tr>td.ui-widget-deleted-row-checkbox  .ui-chkbox{
        display: none;
        }
    //Deleted row
    ::ng-deep .ui-datatable tbody > tr.ng-star-inserted.ui-widget-deleted-row{
        background-color:$deleted-row-color;
    } 

    ::ng-deep  .ui-datatable table
    {
        table-layout:auto !important;
        overflow-y: scroll !important; 
    }
    ::ng-deep .ui-datatable-tablewrapper {
        overflow-y: scroll !important; 
        width: auto !important;
    }
    ::ng-deep .ui-datatable-resizable {
        padding-bottom: 1px;
        /* overflow: auto; */
        width: auto !important;
    }

    ::ng-deep .ui-datatable-scrollable-view .ui-datatable-scrollable-body {
       // min-height: 300px;
        border: 1px solid #D5D5D5;
    }

    ::ng-deep .ui-datatable tbody > tr.ui-widget-content.ui-state-highlight{
        background-color: darkkhaki !important; 
    }
    ::ng-deep a.ui-state-highlight , .ui-state-highlight{
        background-color: rgb(64, 153, 83);
        color: black;
    }
    .hoverAction:hover{
        background-color: seagreen;
        color: black;
    }
    ::ng-deep .ui-confirmdialog-message {
        white-space: pre-line;
    }
    ::ng-deep  .ui-datatable tr.ui-datatable-even:hover
    {  background: #78BCFF;
    }
    ::ng-deep .ui-datatable tbody > tr.ui-widget-content.ui-datatable-odd:hover {
        background: #78BCFF;
    }

    .ui-datatable .ui-datatable-thead>tr>th, .ui-datatable .ui-datatable-tfoot>tr>td, .ui-datatable .ui-datatable-data>tr>td {
        border-color: inherit;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        padding: .25em .5em;
        border-width: 1px;
        flex: 2;
        //width:auto !important;
        min-height: 8px;
        min-width: auto !important;
        max-width: 300px !important;
        font-size: 12px;
        padding: 0px !important;
        padding-left: 4px !important;
        color: black;
        text-transform: capitalize;
        white-space: nowrap;
        overflow: hidden;
         display: table-cell;
        text-overflow: ellipsis !important;
        word-wrap: break-word !important;
        /* font-size: 11px; */
        font-family: $default-font-family;
        border-width: 1px;
        border-style: solid;
    }

这篇关于如何设置Primeng数据表列自动适合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆