如何限制列不在使用ngx-datatable创建的表中重新排序,但所有剩余列必须可重新排序

问题描述 投票:0回答:1

我正在使用角度为4的ngx-datatable工具创建一些表格。我需要一列,即。该表的第一列不能重新排序,所有其他列必须是可订购的。任何人都可以帮助我吗?

javascript angular typescript ngx-datatable
1个回答
0
投票

您将需要使用draggable输入属性绑定。

我相信你的component.html,你的ngx-datatable组件看起来像这样。对于第一个ngx-datatable-column,您需要将第一列的draggable属性设置为false。至于其他列,您可以将draggable设置为true,但默认情况下draggable为true,因此实际上不需要指定它。

<ngx-datatable #table class="bootstrap" [columns]="dataColumns">
  <!-- First column is not draggable -->
  <ngx-datatable-column [width]="30" [draggable]="false">
                            ...
  </ngx-datatable-column>
  <!-- The other columns are draggable -->
  <ngx-datatable-column *ngFor="let column of dataColumns| slice:1; let i = index;" name="{{column.name}}" prop="{{column.prop}}" [draggable]="true">
  ...
  </ngx-datatable-column>
</ngx-datatable>

在你的component.ts上,你需要定义你的dataColumns

dataColumns = [
    {
      prop: 'id',
      name: 'ID'
    },
    .
    .
    // other column definitions

]
© www.soinside.com 2019 - 2024. All rights reserved.