Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In angular datatable how to change show records per page options

In jquery data table I can change records per page option by

"aLengthMenu": [[50, 100, 150, 200, -1],
[50, 100, 150, 200, "All"]],

Anyone know how to achieve this in angular?

I tried

$scope.dtOptions = DTOptionsBuilder.newOptions().withOption('order', [1, 'asc']).withDisplayLength(250);

and

$scope.dtOptions = DTOptionsBuilder.newOptions().withOption('order', [1, 'asc']).withOption('LengthMenu', [[50, 100, 150, 200, -1], [50, 100, 150, 200, "All"]])

I want to show 50, 100, 150, 200

I searched at http://l-lin.github.io/angular-datatables/#/api but couldn't found

like image 504
vinothini Avatar asked Jun 25 '15 12:06

vinothini


Video Answer


2 Answers

You were close... use 'lengthMenu' option and only one array:

$scope.dtOptions = DTOptionsBuilder.newOptions().withOption('order', [1, 'asc']).withOption('lengthMenu', [50, 100, 150, 200])
like image 55
Chris Mitchell Avatar answered Sep 27 '22 18:09

Chris Mitchell


I found the answer!

So there is a variable you use in the datatable called $scope.dtOptions and there is a way to add on to that with .withOption('lengthMenu', [50, 100, 150, 200]);

Now, technically that changed the length options not the length, but in my case all I need is to set the lowest length option to the length I want, and I effectively changed the default length of the table.

Example:

$scope.dtOptions =   DTOptionsBuilder.newOptions()
    .withDOM('<"html5buttons"B>lTfgitp')
    .withButtons([])
    .withOption('order', [1, 'asc'])
    .withOption('lengthMenu', [50, 100, 150, 200]);
like image 41
Ted Carbone Avatar answered Sep 27 '22 18:09

Ted Carbone