检测用户何时更改了 sortable table 的顺序
Detect when the user has changed the order of a sortable table
我目前正在尝试查看是否有一种方法可以检测用户何时更改 sortable table 的顺序。我用代码
设置了 table
<table class="table table-striped table-hover" id="captureTable">
<thead>
<tr>
<th>Index</th>
<th>elem1</th>
<th>elem2</th>
<th>elem3</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in capture.railLines track by x.ASSET_PK" ng-click="capture.selectLine(x.ASSET_PK)">
<td>{{$index + 1}}</td>
<td>{{x.elem1}}</td>
<td>{{x.elem2}}</td>
<td>{{x.elem3}}</td>
<td><a ng-click="capture.deleteLine(x.elem1)" href="javascript:void(0);">⛔️</a></td>
</tr>
</tbody>
</table>
在外部 JavaScript 文件中 table 与 $('tbody').sortable()
进行排序 table。我知道 $scope.$apply(function () {})
调用,但我似乎找不到使用它的好地方。我的大部分功能都与 $scope
相关联,我不能在这些功能中使用它.
编辑: 我没有使用 sortable 对元素进行实际排序,而是使用它以便用户可以通过单击重新排列行并将它们拖来拖去。
当你创建 table sortable 时,你可以在 table 改变时定义一个回调。例如在你的情况下,
$("tbody").sortable({
change: function(event, ui) {
//Do something, probably with these properties:
//ui.item (the jQuery object of the item being dragged)
//ui.position (the new position of the item as {top, left})
//ui.originalPosition (the original position of the item as {top, left})
}
});
我目前正在尝试查看是否有一种方法可以检测用户何时更改 sortable table 的顺序。我用代码
设置了 table<table class="table table-striped table-hover" id="captureTable">
<thead>
<tr>
<th>Index</th>
<th>elem1</th>
<th>elem2</th>
<th>elem3</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in capture.railLines track by x.ASSET_PK" ng-click="capture.selectLine(x.ASSET_PK)">
<td>{{$index + 1}}</td>
<td>{{x.elem1}}</td>
<td>{{x.elem2}}</td>
<td>{{x.elem3}}</td>
<td><a ng-click="capture.deleteLine(x.elem1)" href="javascript:void(0);">⛔️</a></td>
</tr>
</tbody>
</table>
在外部 JavaScript 文件中 table 与 $('tbody').sortable()
进行排序 table。我知道 $scope.$apply(function () {})
调用,但我似乎找不到使用它的好地方。我的大部分功能都与 $scope
相关联,我不能在这些功能中使用它.
编辑: 我没有使用 sortable 对元素进行实际排序,而是使用它以便用户可以通过单击重新排列行并将它们拖来拖去。
当你创建 table sortable 时,你可以在 table 改变时定义一个回调。例如在你的情况下,
$("tbody").sortable({
change: function(event, ui) {
//Do something, probably with these properties:
//ui.item (the jQuery object of the item being dragged)
//ui.position (the new position of the item as {top, left})
//ui.originalPosition (the original position of the item as {top, left})
}
});