Клейкая ячейка в столбцах таблицы с использованием Angular и CSS - PullRequest
0 голосов
/ 05 февраля 2020

Я создал одну таблицу с динамическими данными c, используя Angular, но мне нужно исправить некоторые столбцы, а другие будут горизонтальной прокруткой. Я объясняю мой код ниже.

<div id="table-scroll" class="table-scroll">
     <div class="table-wrap">
         <table class="main-table">
              <tbody *ngIf="ColumnNames.length > 1"> 
                  <tr *ngFor="let opt of ConfigArr; let i = index;">
                         <td class="fixed-side">
                            {{opt.attrName1}}({{opt.attr1}})
                          </td>
                         <td>
                            {{opt.attrName2}}({{opt.attr2}})
                        </td>
                       <td>
                            <input class="form-control" matInput placeholder="MRP" aria-label="MRP" [value]="opt.MRP">
                       </td>
                      <td>
                         <input class="form-control" matInput placeholder="BaseUnitPrice" aria-label="BaseUnitPrice" [value]="opt.BaseUnitPrice">
                     </td>
                     <td>
                        <input class="form-control" matInput placeholder="DiscountValue" aria-label="DiscountValue" [value]="opt.DiscountValue">
                     </td>
                     <td>
                       <input class="form-control" class="form-control" matInput placeholder="MinBuyQty" aria-label="MinBuyQty" [value]="opt.MinBuyQty">
                      </td>
                      <td>
                        <input class="form-control" matInput placeholder="MinimumPrice" aria-label="MinimumPrice" [value]="opt.MinimumPrice">
                     </td>
                     <td>
                        <input class="form-control" matInput placeholder="TaxPercentage" aria-label="TaxPercentage" [value]="opt.TaxPercentage">
                    </td>
                    <td>
                      <input class="form-control" matInput placeholder="TaxAmount" aria-label="TaxAmount" [value]="opt.TaxAmount">
                    </td>
                    <td>
                       <input class="form-control" matInput placeholder="DiscountPrice" aria-label="DiscountPrice" [value]="opt.DiscountPrice">
                    </td>
                    <td>
                     <input class="form-control" matInput placeholder="MaxBuyQty" aria-label="MaxBuyQty" [value]="opt.MaxBuyQty">
                  </td>
                  <td>
                      <input class="form-control" matInput placeholder="MaximumPrice" aria-label="MaximumPrice" [value]="opt.MaximumPrice">
                     </td>
                  </tr>
             </tbody>

        </table>
    </div>
</div>

CSS ::

.table-scroll {
    position:relative;
    max-width:1000px;
    margin:auto;
    overflow:hidden;
    border:1px solid #000;
}
.table-wrap {
    width:100%;
    overflow:auto;
}
.table-scroll table {
    width:100%;
    margin:auto;
    border-collapse:separate;
    border-spacing:0;
}
.table-scroll th, .table-scroll td {
    padding:5px 10px;
    border:1px solid #000;
    background:#fff;
    white-space:nowrap;
    vertical-align:top;
}
.table-scroll thead, .table-scroll tfoot {
    background:#f9f9f9;
}
.clone {
    position:absolute;
    top:0;
    left:0;
    pointer-events:none;
}
.clone th, .clone td {
    visibility:hidden
}
.clone td, .clone th {
    border-color:transparent
}
.clone tbody th {
    visibility:visible;
    color:red;
}
.clone .fixed-side {
    border:1px solid #000;
    background:#eee;
    visibility:visible;
}
.clone thead, .clone tfoot{background:transparent;}

Здесь у меня есть таблица с динамическими данными c. Поскольку в нем много столбцов, мне нужно исправить первые два столбца, а остальные будут прокручиваться горизонтально. Я сделал в css, но он не работает.

1 Ответ

1 голос
/ 05 февраля 2020

Я надеюсь, это поможет вам!

.table-scroll {
    position:relative;
    max-width:1000px;
    margin:auto;
    overflow:hidden;
    border:1px solid #000;
}
.table-wrap {
    width:100%;
    overflow:auto;
  overflow-x: scroll;
  overflow-y: visible;
  margin-left: 240px;
}
.table-scroll table {
    width:100%;
    margin:auto;
    border-collapse:separate;
    border-spacing:0;
}
.table-scroll th, .table-scroll td {
    padding:5px 10px;
    border:1px solid #000;
    background:#fff;
    white-space:nowrap;
    vertical-align:top;
}
.table-scroll thead, .table-scroll tfoot {
    background:#f9f9f9;
}
.clone {
    position:absolute;
    top:0;
    left:0;
    pointer-events:none;
}
.clone th, .clone td {
    visibility:hidden
}
.clone td, .clone th {
    border-color:transparent
}
.clone tbody th {
    visibility:visible;
    color:red;
}
.clone .fixed-side {
    border:1px solid #000;
    background:#eee;
    visibility:visible;
}
.clone thead, .clone tfoot{background:transparent;}
.fix {
  position: absolute;
  *position: relative; /*ie7*/
  margin-left: -120px;
  width: 100px;
  min-height: 21px;
}
.fix2 {
  position: absolute;
  *position: relative; /*ie7*/
  margin-left: -240px;
  width: 100px;
  min-height: 21px;
}
<div id="table-scroll" class="table-scroll">
     <div class="table-wrap">
         <table class="main-table">
              <tbody *ngIf="ColumnNames.length > 1"> 
                  <tr *ngFor="let opt of ConfigArr; let i = index;">
                         <th class="fix">
                           sfgss
                          </th> 
                         <th class="fix2">
                           sfgss
                          </th>
                       <td>
                            <input class="form-control" matInput placeholder="MRP" aria-label="MRP" [value]="opt.MRP">
                       </td>
                      <td>
                         <input class="form-control" matInput placeholder="BaseUnitPrice" aria-label="BaseUnitPrice" [value]="opt.BaseUnitPrice">
                     </td>
                     <td>
                        <input class="form-control" matInput placeholder="DiscountValue" aria-label="DiscountValue" [value]="opt.DiscountValue">
                     </td>
                     <td>
                       <input class="form-control" class="form-control" matInput placeholder="MinBuyQty" aria-label="MinBuyQty" [value]="opt.MinBuyQty">
                      </td>
                      <td>
                        <input class="form-control" matInput placeholder="MinimumPrice" aria-label="MinimumPrice" [value]="opt.MinimumPrice">
                     </td>
                     <td>
                        <input class="form-control" matInput placeholder="TaxPercentage" aria-label="TaxPercentage" [value]="opt.TaxPercentage">
                    </td>
                    <td>
                      <input class="form-control" matInput placeholder="TaxAmount" aria-label="TaxAmount" [value]="opt.TaxAmount">
                    </td>
                    <td>
                       <input class="form-control" matInput placeholder="DiscountPrice" aria-label="DiscountPrice" [value]="opt.DiscountPrice">
                    </td>
                    <td>
                     <input class="form-control" matInput placeholder="MaxBuyQty" aria-label="MaxBuyQty" [value]="opt.MaxBuyQty">
                  </td>
                  <td>
                      <input class="form-control" matInput placeholder="MaximumPrice" aria-label="MaximumPrice" [value]="opt.MaximumPrice">
                     </td>
                  </tr>
             </tbody>

        </table>
    </div>
</div>
...