Skip to content

Commit

Permalink
Refactor #2310
Browse files Browse the repository at this point in the history
  • Loading branch information
yigitfindikli committed Sep 24, 2021
1 parent 5ec6e64 commit b5de159
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
21 changes: 9 additions & 12 deletions src/components/paginator/JumpToPageInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,34 @@ import { InputNumber } from '../inputnumber/InputNumber';
export class JumpToPageInput extends Component {

static defaultProps = {
value: null,
page: null,
pageCount: null,
disabled: false
rows: null,
disabled: false,
onChange: null
}

static propTypes = {
value: PropTypes.number,
page: PropTypes.number,
pageCount: PropTypes.number,
rows: PropTypes.number,
disabled: PropTypes.bool,
onChange: PropTypes.func
}

constructor(props) {
super(props)

this.onChange = this.onChange.bind(this);
this.inputChange = this.inputChange.bind(this);
}

onChange(event) {
inputChange(event) {
if (this.props.onChange) {
this.props.onChange({
event: event.originalEvent,
value: event.value
});
this.props.onChange(this.props.rows * (event.value - 1), this.props.rows);
}
}

render() {
return (
<InputNumber value={this.props.value} onChange={this.onChange} className="p-paginator-page-input" disabled={this.props.disabled} />
<InputNumber value={this.props.page} onChange={this.inputChange} className="p-paginator-page-input" disabled={this.props.disabled} />
)
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/paginator/Paginator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ interface PaginatorCurrentPageReportOptions {
}

interface PaginatorJumpToPageInputOptions {
value: number;
page: number;
pageCount: number;
rows: number
disabled: boolean;
onChange(first:number, rows: number): void;
}

interface PaginatorTemplateOptions {
Expand Down
7 changes: 6 additions & 1 deletion src/components/paginator/Paginator.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class Paginator extends Component {
this.changePageToNext = this.changePageToNext.bind(this);
this.changePageToLast = this.changePageToLast.bind(this);
this.onRowsChange = this.onRowsChange.bind(this);
this.changePage = this.changePage.bind(this);
this.onPageLinkClick = this.onPageLinkClick.bind(this);
}

Expand Down Expand Up @@ -118,6 +119,10 @@ export class Paginator extends Component {
return Math.floor(this.props.first / this.props.rows);
}

currentPage() {
return this.getPageCount() > 0 ? this.getPage() + 1 : 0;
}

empty() {
let pageCount = this.getPageCount()
return pageCount === 0;
Expand Down Expand Up @@ -199,7 +204,7 @@ export class Paginator extends Component {
rows={this.props.rows} totalRecords={this.props.totalRecords} template={template} />;
break;
case 'JumpToPageInput':
element = <JumpToPageInput page={this.getPage()} onChange={this.changePage} disabled={this.empty()} />;
element = <JumpToPageInput key={key} rows={this.props.rows} page={this.currentPage()} onChange={this.changePage} disabled={this.empty()} />;
break;

default:
Expand Down

0 comments on commit b5de159

Please sign in to comment.