Disable column sorting not working for multiple angularjs datatables

心已入冬 提交于 2019-12-01 20:45:00

OK. Dont know where to start, but you a had broad range of errors in your code (no offense).

  • Never declared x
  • Never actually used x
  • Never actually used dtColumnDefs

And more...After some debugging the overall setup did work. However, your biggest problem was the mix of ng-repeat combined with the datatable directive combined with redeclaring the same properties over and over. It was easy to fix the code, but not easy to overcome this extreme race condition. Spent an hour trying to work it out, but it is not possible without a lot of $compile's, $apply's and $timeout's.

It really do not have to be so complicated. As I understand you had two issues 1) notSortable did not work 2) you could have different columns (properties) for different lists. Simply let dataTables render the data, and declare dtColumns dynamically each time a new list is selected :

var columns = [];
for (var prop in $scope.list[0] ) {
  columns.push({ data: prop })
}
$scope.x.dtColumns = columns;

Set $scope.list as data source :

$scope.x.dtOptions = DTOptionsBuilder.newOptions()
   .withOption('data', $scope.list)

render the "dataTables way" :

<table datatable=""  ....></table>

forked plnkr -> http://plnkr.co/edit/afqKW5uKW7Skfnm62zfq?p=preview

Try using square brackets inside the dtColumnDefspush like

$scope.x.dtColumnDefs.push(DTColumnDefBuilder.newColumnDef([i]).notSortable()); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!