【问题标题】:Drag and drop column to another row in table using ngx-sortablejs使用 ngx-sortablejs 将列拖放到表中的另一行
【发布时间】:2020-10-14 09:52:38
【问题描述】:

我试图将一行的列拖到另一行,但它不能拖放到另一行的列数组。我有以下类型的数组(示例数据数组)。

[
 { // row
    key: value,
      cols: [{ key: value }] // cols array
   },
  //n numers of row
]

我的代码。

<table id="id">
    <tbody sortablejs ngDefaultControl [(ngModel)]="Array">
        <tr *ngFor="let item of Array; let i = index">
            <td class="myRowClass sort-disabled">
                <!-- index logic -->
            </td>
            <td class="myRowClass sort-disabled">
                <!--logic -->
            </td>
            <td sortablejs>
                <div *ngFor="let cell of item.cols" class="divSize">
                    <!-- column logic -->
                </div>
            </td>
        </tr>
    </tbody>
</table>

【问题讨论】:

    标签: javascript angular drag-and-drop sortablejs


    【解决方案1】:

    通过使用[sortablejsOptions]="options",我实现了我的功能。

    <table id="id">
     <tbody [sortablejs]="Array" [sortablejsOptions]="Array">
      <tr *ngFor="let item of Array">
       <td class="myRowClass sort-disabled">
        <!-- index logic -->
       </td>
       <td>
        <!--row logic -->
       </td>
       <td [sortablejs]="item.cols" [sortablejsOptions]="options">
        <div *ngFor="let cell of item.cols; let j = index">
         <!--column logic -->
        </div>
       </td>
      </tr>
     </tbody>
    </table>
    

    .ts 文件组名中的选项必须相同。

    options: Options = {
        group: { name: "test" }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-11-12
      • 2020-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-15
      • 1970-01-01
      相关资源
      最近更新 更多