bafix2203
bafix2203

Reputation: 541

dataTables AngularJS options sort

Here is my table : https://codepen.io/anon/pen/dzjPro I wan't to sort only first 2 columns, the column Position was not sortable.

Code :

$scope.dataTableOpt = {

  "aLengthMenu": [[10, 50, 100,-1], [10, 50, 100,'All']],
  "aoSearchCols": [
      null
    ],
  };

This doesn't work :

 $scope.dataTableOpt = {

      "aLengthMenu": [[10, 50, 100,-1], [10, 50, 100,'All']],
      "aoSearchCols": [
          null
        ],
      "aoColumnDefs": [
            { "aDataSort": [ 0,1 ], "aTargets": [ 0,1 ] }
        ],
      };

Thanks for answers in advance.

Upvotes: 1

Views: 1082

Answers (1)

davidkonrad
davidkonrad

Reputation: 85528

Seems to me you have picked up some sunsetted legacy code. Use columnDefs and orderable instead :

$scope.dataTableOpt = {
  lengthMenu: [[10, 50, 100,-1], [10, 50, 100,'All']],
  columnDefs: [
    { targets: 2, orderable: false }
  ]
};

targets is the zero based column index. It can be an array of indexes.

Also take a look at angular datatables directives. You may face problems with rendering and so on, if you use "pure" jQuery datatables along with angular.

Upvotes: 1

Related Questions