【问题标题】:Angular Smart Table drag headers with different td elements具有不同 td 元素的 Angular Smart Table 拖动标题
【发布时间】:2016-01-03 22:26:03
【问题描述】:

我正在为数据表使用 Angular Smart Table 插件。我正在使用thisplnkr 用于拖动标题功能。我试过了,效果很好,但问题是我有不同的 td 元素,例如复选框、收音机等。

例如在它的代码中

    <tr ng-repeat="row in rowCollection">
    <td ng-repeat="col in columns">{{row[col]}}</td>
    </tr>

这里 td 的所有元素都是相似的,我想要不同的元素,我不能使用 ng-repeat 。

这是我的一个

<tr ng-repeat="t in displayedCollection">
            <td>{{t.Id}}</td>
            <td>{{t.Title}}</td>
            <td>{{t.Content}}</td>
            <td>{{t.Status}}</td>
            <td><input type="checkbox" ng-model="t.IsActive" disabled="disabled"></td>
            <td><input type="checkbox" ng-model="t.IsCommentAllowed" disabled="disabled"></td>
            <td><input type="checkbox" ng-model="t.IsRatingAllowed" disabled="disabled"></td>
        </tr>

在此代码中,标题正在拖动,但其列没有。此代码使用lrDragNDrop 插件进行拖放。我应该怎么做可能需要帮助?

【问题讨论】:

标签: angularjs datatable drag-and-drop smart-table


【解决方案1】:

这是一个有效的plnkr ...

想法是将“其他”类型的列添加到列列表中,然后使用 ng-if。希望对你有用。

标记

 <tr ng-repeat="row in rowCollection">
   <td ng-repeat="col in columns">
     <span ng-if="col != 'cb'">{{row[col]}}</span>
     <span ng-if="col == 'cb'">
       <input type="checkbox" ng-model="row.IsActive">
     </span>
   </td>
 </tr>

JS

$scope.columns=['cb', 'firstName', 'lastName','age','email','balance'];

** 已更新(使用 ng-switch 代替 ng-if)

      <tr ng-repeat="row in rowCollection">
          <td ng-repeat="col in columns" ng-switch="col">
            <span ng-switch-default>{{row[col]}}</span>
            <span ng-switch-when="cb">
              <input type="checkbox" ng-model="row.IsActive">
            </span>
          </td>
      </tr>

【讨论】:

  • 好的 明白了,只需使用 nf-if 检查符合条件的列名称
  • @Ghazanfar :是的,ng-switch 会更好......我会更新答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 2016-06-29
  • 2017-02-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多