Socket
Socket
Sign inDemoInstall

ngc-pagination

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngc-pagination - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

25

module/ngc-pagination.component.ts

@@ -6,4 +6,4 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject';

totalItens: number;
itensPerPage: number;
currentPage: number;
itensPerPage?: number;
currentPage?: number;
range?: number;

@@ -37,2 +37,4 @@ change_after?: boolean;

this.config.subscribe( v => {
this.useDefaultValues();
this.createPagination();

@@ -44,2 +46,20 @@ this.createExibition();

private useDefaultValues() {
if(!this.config.getValue().currentPage) {
this.config.getValue().currentPage = 1;
}
if(!this.config.getValue().range) {
this.config.getValue().range = 10;
}
if(!this.config.getValue().itensPerPage) {
this.config.getValue().itensPerPage = 10;
}
if(this.config.getValue().change_after === undefined) {
this.config.getValue().change_after = false;
}
}
public goTo(e, page) {

@@ -84,2 +104,3 @@

private createExibition() {
let start = Math.floor((this.config.getValue().currentPage-1) - this.config.getValue().range/2 < 0 ? 0 : this.config.getValue().currentPage-this.config.getValue().range/2);

@@ -86,0 +107,0 @@ let end = Math.floor(this.config.getValue().currentPage < this.config.getValue().range/2 ? this.config.getValue().range : (this.config.getValue().currentPage) + this.config.getValue().range/2);

2

package.json
{
"name": "ngc-pagination",
"version": "0.0.2",
"version": "0.0.3",
"description": "Simple pagination for Angular v2+",

@@ -5,0 +5,0 @@ "scripts": {

@@ -53,3 +53,3 @@ # ngc-pagination

1 - config our pagination
1 - Configure the pagination

@@ -76,13 +76,18 @@ ```Typescript

// pagination config to send to component
createPagination() {
this.paginationConfig = new BehaviorSubject({
totalItens: 300,
itensPerPage: 10,
currentPage: 1,
range: 10,
change_after: false
totalItens: 300, // required
itensPerPage: 10, // 10 is the default
currentPage: 1, // 1 is the default
range: 10, // 10 is the default
change_after: false // false is the default
});
}
/*
change_after property when is true, all user events isn't applied into the view when the
current page is changed. A good example of your usage is if you want to update the current
page in the UI only your request is done for example.
*/
// to listener ngc-pagination events.

@@ -97,6 +102,8 @@ events(event) {

2 - Our pagination template
2 - The pagination template
```HTML
<ngc-pagination #pagination [config]="paginationConfig" (paginationEvents)="events($event)">
<ngc-pagination #pagination
[config]="paginationConfig"
(paginationEvents)="events($event)">

@@ -155,3 +162,45 @@ <!--

Well, with only that you can see this result:
![](http://g.recordit.co/RDtZOmZ6kE.gif)
Cool! With your `BehaviorSubject` you can emit events and the `ngu-pagination` will react the property changes.
If you need change the currentPage
```Typescript
this.paginationConfig.next({
...this.paginationConfig.getValue(), // with this you get the active properties like totalItens, range...
currentPage: event.goTo // you only change the currentPage property
})
```
If you need to change the pagination range
```Typescript
this.paginationConfig.next({
...this.paginationConfig.getValue(),
range: 5
})
```
If change_after property is true you can update the view after 2s 'simulating a request'
```Typescript
// passing (paginationEvents)="events($event)" to listener ngc-pagination events
events(event) {
// simulate request
setTimeout( () => {
// update the currentPage UI when only the request is back.
this.paginationConfig.next({
...this.paginationConfig.getValue(),
currentPage: event.goTo
})
},2000);
}
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc