任何人都知道如何从外部排序功能更新ng-grid?
我已将userExternalSort设置为true.然后,我有这个代码(Coffeescript):
$scope.$on 'ngGridEventSorted', (event, data) ->
console.log "Before sort " + $scope.recs[0].location
$scope.recs.sort (a, b) ->
if data.directions[0] = "asc"
return a.location > b.location ? 1 : -1
else
return a.location > b.location ? -1 : 1
console.log "After sort " + $scope.recs[0].location
Run Code Online (Sandbox Code Playgroud)
我的功能实际上排序.但是,ng-grid永远不会更新.我已经尝试了$ scope.$ apply()无济于事 - 它已经在$ apply中了.
谢谢.
您的代码存在一些问题,为了帮助您完全使用代码,我需要查看您的gridOptions,以便我可以看到您是否正确更新数据.如果我们也可以通过一些代码来获取一个代码也可能会有所帮助
第一件事是该选项是"useExternalSort"并且实际上将关闭ngGridEventSorted事件,因此您需要使用类似这样的内容:
$scope.$watch 'gridOptions.ngGrid.config.sortInfo', (newVal,oldVal) ->
console.log "Before sort " + $scope.recs[0].location
$scope.recs.sort (a, b) ->
if data.directions[0] = "asc"
return a.location > b.location ? 1 : -1
else
return a.location > b.location ? -1 : 1
console.log "After sort " + $scope.recs[0].location
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3805 次 |
| 最近记录: |