Disabling Angularjs Datatable Sorting For Specified Columns
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.
Solution 1:
Today I got the same issue and here is the what I have found; In my case I wanted to remove sorting feature from first column since it just contain a check box.
According to the official documentation this is the code block;
app.controller('exceptionViewCtrl', ['$scope', 'DTColumnDefBuilder', function ($scope, $routeParams, DTColumnDefBuilder) {
$scope.dtColumnDefs = [DTColumnDefBuilder.newColumnDef(0).notSortable()];
}]);
But this is not worked; Then I figure out even if I disable sorting for a column, the dataTables sort order
still remain. By default order is [0, 'asc']
. So you need to additionally set order
to target some other column instead.
So the complete html+angular code as follows;
HTML
<table datatable="" id="example2" class="table table-bordered table-hover" dt-options="dtOptions" dt-column-defs="dtColumnDefs">//table data
</table>
Angular
app.controller('exceptionViewCtrl', ['$scope', 'DTColumnDefBuilder', 'DTOptionsBuilder', function ($scope, DTColumnDefBuilder, DTOptionsBuilder) {
$scope.dtOptions = DTOptionsBuilder.newOptions().withOption('order', [1, 'asc']);
$scope.dtColumnDefs = [DTColumnDefBuilder.newColumnDef(0).notSortable()];
}]);
Solution 2:
try it:
$scope.vm.dtOptions = DTOptionsBuilder.newOptions()
.withOption('order', [0, 'asc']);
$scope.vm.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(1).notSortable(),
DTColumnDefBuilder.newColumnDef(3).notSortable()
];
});
Post a Comment for "Disabling Angularjs Datatable Sorting For Specified Columns"