0

I am working with angularjs data table where I don't need sorting for all the columns. So I want to disable sorting for specified columns. I want to disable sorting for column no. 2 and 4 for the below case.But i am receiving DTColumnDefBuilder is not defined error.

var app = angular.module('myApp',['datatables']);
app.controller('MyCtrl', function($scope,DTOptionsBuilder,DTColumnBuilder) {

    $scope.list = [
        {"eid":"10","ename":"nam1","sales":"20"},
        {"eid":"20","ename":"nam2","sales":"20"},
        {"eid":"30","ename":"nam3","sales":"20"},
        {"eid":"40","ename":"nam4","sales":"20"}
    ];
    $scope.vm = {};

$scope.vm.dtOptions = DTOptionsBuilder.newOptions()
      .withOption('order', [0, 'asc']);
$scope.vm.dtColumnDefs = [
   DTColumnDefBuilder.newColumnDef(1).notSortable(),
   DTColumnDefBuilder.newColumnDef(3).notSortable()
];

});
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
  <script src="http://phpflow.com/demo/angular_datatable_demo/angular-datatables.min.js"></script>
  <script src="http://phpflow.com/demo/angular_datatable_demo/jquery.dataTables.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
  <link rel="stylesheet" href="http://phpflow.com/demo/angular_datatable_demo/datatables.bootstrap.css"> 
</head>
<div class="container">
<div ng-app="myApp" ng-controller="MyCtrl">
<table  class="table table-striped table-bordered" dt-options="vm.dtOptions" dt-column-defs="vm.dtColumnDefs" datatable="ng">
    <thead>
      <tr>
	 <th>Employee ID</th>
	<th>name</th>
	<th>sales</th>
	<th>details</th>

</thead>
    <tbody>
  
   <tr ng-repeat="data in list">
      <td> {{ data.eid }} </td>
      <td> {{ data.ename }} </td>
      <td> {{ data.sales }} </td>
      <td>view</td>
</tr>
</tbody>
</table>
</div>

1 Answer 1

1

You forgot to inject DTColumnDefBuilder to your controller definition function constructor.

var app = angular.module('myApp',['datatables']);
app.controller('MyCtrl', function($scope,DTOptionsBuilder,DTColumnBuilder,DTColumnDefBuilder) {

    ...
Sign up to request clarification or add additional context in comments.

1 Comment

can you provide one more help ? I am working on a table which has dynamic columns except first and last two columns.how to specify column number in such case ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.