Pagination: maxLoads
This commit is contained in:
parent
f8ec125958
commit
270f16d0db
|
@ -9,10 +9,10 @@
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<div ng-show="$ctrl.showFilter" class="filter">
|
<div ng-show="$ctrl.showFilter" class="filter">
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
model="$ctrl.search"
|
model="$ctrl.search"
|
||||||
class="search"
|
class="search"
|
||||||
ng-blur="$ctrl.onFocusOut()"
|
ng-blur="$ctrl.onFocusOut()"
|
||||||
label = "Search">
|
label = "Search">
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
</div>
|
</div>
|
||||||
<div class="list" tabindex="-1">
|
<div class="list" tabindex="-1">
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
ng-if="!$ctrl.model.isLoading"
|
ng-if="!$ctrl.model.isLoading"
|
||||||
icon="more_horiz"
|
icon="more_horiz"
|
||||||
vn-tooltip="Load more"
|
vn-tooltip="Load more"
|
||||||
ng-click="$ctrl.model.loadMore()">
|
ng-click="$ctrl.onLoadClick()">
|
||||||
</vn-icon-button>
|
</vn-icon-button>
|
||||||
<vn-spinner
|
<vn-spinner
|
||||||
ng-if="$ctrl.model.isLoading"
|
ng-if="$ctrl.model.isLoading"
|
||||||
|
|
|
@ -10,11 +10,14 @@ import './style.scss';
|
||||||
* @property {String} scrollSelector The the scrollable element selector
|
* @property {String} scrollSelector The the scrollable element selector
|
||||||
* @property {HTMLElement} scrollElement The scrollable element
|
* @property {HTMLElement} scrollElement The scrollable element
|
||||||
* @property {Number} scrollOffset The distance, in pixels, until the end that activates the loading of the next rows
|
* @property {Number} scrollOffset The distance, in pixels, until the end that activates the loading of the next rows
|
||||||
|
* @property {Number} maxLoads The maximum of loads that are automatically performed on scroll, 0 for no limit
|
||||||
*/
|
*/
|
||||||
class Pagination extends Component {
|
class Pagination extends Component {
|
||||||
constructor($element, $scope) {
|
constructor($element, $scope) {
|
||||||
super($element, $scope);
|
super($element, $scope);
|
||||||
this.scrollOffset = 300;
|
this.scrollOffset = 500;
|
||||||
|
this.maxLoads = 5;
|
||||||
|
this.nLoads = 0;
|
||||||
this.scrollHandler = e => this.onScroll(e);
|
this.scrollHandler = e => this.onScroll(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,14 +53,23 @@ class Pagination extends Component {
|
||||||
let scrollElement = this.scrollElement;
|
let scrollElement = this.scrollElement;
|
||||||
let shouldLoad =
|
let shouldLoad =
|
||||||
scrollElement.scrollTop + scrollElement.clientHeight >= (scrollElement.scrollHeight - this.scrollOffset)
|
scrollElement.scrollTop + scrollElement.clientHeight >= (scrollElement.scrollHeight - this.scrollOffset)
|
||||||
&& !this.model.isLoading;
|
&& !this.model.isLoading
|
||||||
|
&& (this.maxLoads <= 0 || this.nLoads < this.maxLoads);
|
||||||
|
|
||||||
if (shouldLoad) {
|
if (shouldLoad) {
|
||||||
|
this.nLoads++;
|
||||||
this.model.loadMore();
|
this.model.loadMore();
|
||||||
this.$.$apply();
|
this.$.$apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onLoadClick() {
|
||||||
|
if (this.maxLoads > 0 && this.nLoads == this.maxLoads)
|
||||||
|
this.nLoads = 0;
|
||||||
|
|
||||||
|
this.model.loadMore();
|
||||||
|
}
|
||||||
|
|
||||||
$onDestroy() {
|
$onDestroy() {
|
||||||
this.scrollElement = null;
|
this.scrollElement = null;
|
||||||
}
|
}
|
||||||
|
@ -69,7 +81,8 @@ ngModule.component('vnPagination', {
|
||||||
model: '<',
|
model: '<',
|
||||||
scrollSelector: '@?',
|
scrollSelector: '@?',
|
||||||
scrollElement: '<?',
|
scrollElement: '<?',
|
||||||
scrollOffset: '<?'
|
scrollOffset: '<?',
|
||||||
|
maxLoads: '<?'
|
||||||
},
|
},
|
||||||
controller: Pagination
|
controller: Pagination
|
||||||
});
|
});
|
||||||
|
|
|
@ -58,7 +58,10 @@ let baseConfig = {
|
||||||
`${__dirname}/client`,
|
`${__dirname}/client`,
|
||||||
__dirname,
|
__dirname,
|
||||||
'node_modules'
|
'node_modules'
|
||||||
]
|
],
|
||||||
|
alias: {
|
||||||
|
'vn-loopback': `${__dirname}/services/loopback`
|
||||||
|
}
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.optimize.CommonsChunkPlugin({
|
new webpack.optimize.CommonsChunkPlugin({
|
||||||
|
|
Loading…
Reference in New Issue