Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide redundant Page Size buttons #648

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ng-table/pager.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class="ng-cloak ng-table-pager" ng-if="params.data.length">
<div ng-if="params.settings().counts.length" class="ng-table-counts btn-group pull-right">
<button ng-repeat="count in params.settings().counts" type="button"
ng-show="params.maxCount(count)"
ng-class="{'active':params.count() == count}"
ng-click="params.count(count)" class="btn btn-default">
<span ng-bind="count"></span>
Expand All @@ -17,3 +18,4 @@
</li>
</ul>
</div>

22 changes: 22 additions & 0 deletions src/scripts/03-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ app.factory('NgTableParams', ['$q', '$log', 'ngTableDefaults', function($q, $log

this.data = [];

/**
* @maxCount method
* @name NgTableParams#parameters
* @description Determines if a page size button should be visible based on # of rows in table
*
* @param {count} the current count of the page size button
* @returns {boolean} false if the button should be hidden, true if it should be visible
*/
this.maxCount = function(count){
var total = this.total();
if (total > 0 && count <= total) {
return true;
}
if (total > this.settings().counts[this.settings().counts.length-1]) {
return true;
}
if (total < count && total > this.settings().counts[this.settings().counts.indexOf(count)-1]) {
return true;
}
return false;
};

/**
* @ngdoc method
* @name NgTableParams#parameters
Expand Down