Skip to content
This repository was archived by the owner on Nov 19, 2021. It is now read-only.

Commit 0da9483

Browse files
author
Garcia Marin
committed
detail pagination
1 parent b14bd94 commit 0da9483

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

oasp4js-sample/src/app/components/details/service/Details.service.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ export class DetailsService{
2121
}
2222

2323
if(n === 0){n = 100000}
24-
25-
c.setNumber(n+1);
26-
c.setTitle(c.getTitle())
27-
c.setStatus('ORDERED');//by default
28-
c.setPrice(c.getPrice());
29-
this.commands.push(c);
24+
let d = new Command(n+1, c.getTitle(),'ORDERED', c.getPrice(), "...");
25+
this.commands.push(d);
3026
}
3127

3228
removeCommand(c:Command){
33-
let index = this.commands.indexOf(c);
34-
this.commands.splice(index,1);
29+
// debugger
30+
// let index = this.commands.indexOf(c);
31+
for(let i = 0; i < this.commands.length ; i ++){
32+
if(this.commands[i].number === c.number){
33+
this.commands.splice(i,1);
34+
break;
35+
}
36+
}
3537
}
3638

3739
resetCommands(){

oasp4js-sample/src/app/oasp/oasp-ui/table-pagination/Pagination.component.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,41 @@ import {Component, OnChanges, EventEmitter} from '@angular/core'
77
outputs: ['paginationList']
88
})
99

10-
export class PaginationComponent implements OnChanges{
10+
export class PaginationComponent{
1111

1212
list;
1313
showList;
1414

1515
currentPage: number = 1;
1616
pageView: number = 1;
1717

18+
initRowsPerPage: number;
1819
rowsPerPage: number;
1920
numberPages: number;
2021

2122
paginationList = new EventEmitter();
2223

2324
ngOnChanges(){
24-
debugger
2525
if(this.list){
26+
27+
if(!this.initRowsPerPage) {
28+
this.initRowsPerPage = this.rowsPerPage;
29+
}
30+
2631
if(this.rowsPerPage > this.list.length){
2732
this.rowsPerPage = this.list.length;
33+
} else {
34+
this.rowsPerPage = this.initRowsPerPage;
2835
}
2936

3037
this.showList = this.list.slice(this.rowsPerPage * (this.currentPage - 1), this.rowsPerPage * (this.currentPage - 1) + this.rowsPerPage);
3138
this.numberPages = Math.ceil(this.list.length / this.rowsPerPage);
32-
this.paginationList.emit(this.showList)
39+
this.paginationList.emit(this.showList);
40+
41+
if(this.showList.length <= 0){
42+
this.changePage(this.currentPage - 1, 0);
43+
}
44+
3345
}
3446
}
3547

0 commit comments

Comments
 (0)