javascript - 在 angularjs 中对表的行进行排序或重新排列(拖放)

标签 javascript angularjs angularjs-directive html-table

我想要具有重新排列表中行的功能(使用拖放对行进行排序)。 模型中行排列的索引也应该改变。

我怎样才能做类似的事情:http://jsfiddle.net/tzYbU/1162/ 使用 Angular Directive(指令)?

我正在生成表:

<table id="sort" class="table table-striped table-bordered">
  <thead>
    <tr>
      <th class="header-color-green"></th>
      <th ng-repeat="titles in Rules.Titles">{{titles.title}}</th>
    </tr>
  </thead>
  <tbody ng-repeat="rule in Rules.data">
    <tr>
      <td class="center"><span>{{rule.ruleSeq}}</span></td>
      <td ng-repeat="data in rule.ruleData">{{statusArr[data.value]}}</td>
    </tr>
  </tbody>
</table>

最佳答案

我做到了。请参阅下面我的代码。

HTML

<div ng:controller="controller">
    <table style="width:auto;" class="table table-bordered">
        <thead>
            <tr>
                <th>Index</th>
                <th>Count</th>
            </tr>
        </thead>
        <tbody ui:sortable ng:model="list">
            <tr ng:repeat="item in list" class="item" style="cursor: move;">
                <td>{{$index}}</td>
                <td>{{item}}</td>
            </tr>
        </tbody>{{list}}
        <hr>
</div>

指令 (JS)

var myapp = angular.module('myapp', ['ui']);

myapp.controller('controller', function ($scope) {
    $scope.list = ["one", "two", "thre", "four", "five", "six"];
});

angular.bootstrap(document, ['myapp']);

关于javascript - 在 angularjs 中对表的行进行排序或重新排列(拖放),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18614695/

相关文章:

javascript - 使用正则表达式解析 url,模式与可选字符串不匹配

javascript - 尽管验证错误仍提交 Angular 表单

javascript - 如何使用 Angular $http GET 调用填充 Kendo 网格

javascript - AngularJS - 指令包装而不丢失与 Controller 的连接

javascript - 使用尾声,是否可以在没有关联的情况下取回资源?

javascript - 在 onchange 和通过文本框将数字存储在数组中时遇到问题

javascript - 如何使相对 Div 可拖动?

angularjs - 你如何让 Angular Bootstrap 工具提示工作?

javascript - AngularJS 在同一元素上有多个指令,$compile :multidir ERROR

javascript - 将函数表达式存储在 angularjs 指令的链接函数中并通过 ng-click 使用它