Skip to content

Commit

Permalink
Fixed #163
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici committed Oct 31, 2017
1 parent 48b9d9c commit 716d3c6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/components/datatable/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class DataTable extends Component {
first: null,
rows: null,
totalRecords: null,
rowsPerPageOptions: null,
lazy: false,
sortField: null,
sortOrder: null,
Expand Down Expand Up @@ -98,6 +99,7 @@ export class DataTable extends Component {
first: PropTypes.number,
rows: PropTypes.number,
totalRecords: PropTypes.number,
rowsPerPageOptions: PropTypes.array,
lazy: PropTypes.bool,
sortField: PropTypes.string,
sortOrder: PropTypes.number,
Expand Down Expand Up @@ -197,7 +199,7 @@ export class DataTable extends Component {
let className = 'ui-paginator-' + position;

return <Paginator first={this.state.first} rows={this.state.rows} className={className} onPageChange={this.onPageChange} template={this.props.paginatorTemplate}
totalRecords={totalRecords} />;
totalRecords={totalRecords} rowsPerPageOptions={this.props.rowsPerPageOptions}/>;
}

onSort(event) {
Expand Down
6 changes: 6 additions & 0 deletions src/components/paginator/Paginator.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
margin-left: .063em;
margin-right: .063em;
text-decoration: none;
vertical-align: middle;
}

.ui-paginator .ui-paginator-page,
Expand Down Expand Up @@ -53,4 +54,9 @@

.ui-paginator a.ui-state-disabled {
outline: 0 none;
}

.ui-paginator .ui-dropdown {
min-width: 4em;
margin-left: .375em;
}
5 changes: 2 additions & 3 deletions src/components/paginator/Paginator.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ export class Paginator extends Component {
}

onRowsChange(event) {
this.changePage(0, this.props.rowsPerPageOptions[event.target.selectedIndex]);
event.preventDefault();
this.changePage(0, event.value);
}

render() {
Expand Down Expand Up @@ -165,7 +164,7 @@ export class Paginator extends Component {
break;

case 'RowsPerPageDropdown':
element = <RowsPerPageDropdown key={key} options={this.props.rowsPerPageOptions} onChange={this.onRowsChange} />;
element = <RowsPerPageDropdown key={key} value={this.props.rows} options={this.props.rowsPerPageOptions} onChange={this.onRowsChange} />;
break;

case 'CurrentPageReport':
Expand Down
11 changes: 9 additions & 2 deletions src/components/paginator/RowsPerPageDropdown.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import {Dropdown} from '../dropdown/Dropdown';

export class RowsPerPageDropdown extends Component {

static defaultProps = {
options: null,
value: null,
onChange: null
}

static propsTypes = {
options: PropTypes.array,
value: PropTypes.number,
onChange: PropTypes.func
}

render() {
if(this.props.options) {
let options = this.props.options.map((opt, i) => <option key={opt} value={opt}>{opt}</option>);
let options = this.props.options.map((opt, i) => {
return {label: opt, value: opt};
});

return <select className="ui-paginator-rpp-options ui-widget ui-state-default" onChange={this.props.onChange}>{options}</select>;
return (
<Dropdown value={this.props.value} options={options} onChange={this.props.onChange} />
);
}
else {
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/showcase/datatable/DataTablePaginatorDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class DataTablePaginatorDemo extends Component {
</div>

<div className="content-section implementation">
<DataTable value={this.state.cars} paginator={true} rows={10}>
<DataTable value={this.state.cars} paginator={true} rows={10} rowsPerPageOptions={[5,10,20]} >
<Column field="vin" header="Vin" />
<Column field="year" header="Year" />
<Column field="brand" header="Brand" />
Expand Down Expand Up @@ -90,7 +90,7 @@ export class DataTablePaginatorDemo extends Component {
</div>
<div className="content-section implementation">
<DataTable value={this.state.cars} paginator={true} rows={10}>
<DataTable value={this.state.cars} paginator={true} rows={10} rowsPerPageOptions={[5,10,20]}>
<Column field="vin" header="Vin" />
<Column field="year" header="Year" />
<Column field="brand" header="Brand" />
Expand Down

0 comments on commit 716d3c6

Please sign in to comment.