Skip to content

Commit

Permalink
Merge pull request #194 from eddyson-de/move-rows-per-page-to-pager
Browse files Browse the repository at this point in the history
move page size default to Pager
  • Loading branch information
jochenberger committed Nov 29, 2016
2 parents 227294a + c21d442 commit e4c9b9d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
11 changes: 3 additions & 8 deletions lib/Ardagryd.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import GridCell from './GridCell';
import GridRow from './GridRow';


import { DESCENDING, DEFAULT_ITEMS_PER_PAGE } from './constants';
import { DESCENDING } from './constants';

import { filterConfigFromProp, sortConfigFromProp } from './utils';
import { columnsConfig as columnsConfigPropType, sortConfig as sortConfigPropType, filterConfig as filterConfigPropType, globalConfig as globalConfigPropType } from './proptypes';
Expand Down Expand Up @@ -198,10 +198,9 @@ const buildConfigFromProps = (props) => {
} else if (type === Pager){
let { rowsPerPage } = props;
if (rowsPerPage < 1){
rowsPerPage = DEFAULT_ITEMS_PER_PAGE;
throw new Error(`Invalid prop value for "rowsPerPage" on "Pager" component: ${rowsPerPage}. Using default: ${DEFAULT_ITEMS_PER_PAGE}.`);
throw new Error(`Invalid prop value for "rowsPerPage" on "Pager" component: ${rowsPerPage}.`);
}
result.paging = rowsPerPage ? rowsPerPage : DEFAULT_ITEMS_PER_PAGE;
result.paging = rowsPerPage;
result.pager = child;
} else if (type === GridCell){
result.cell = child.props;
Expand Down Expand Up @@ -260,9 +259,6 @@ const Ardagryd = (props)=>{
const usePaging = paging !== undefined && paging !== false && objects.length > paging;
let pager = null;
if (usePaging){
if (paging < 1){
throw new Error(`Invalid value for config.paging: ${paging}`);
}
pagedObjects = objects.slice(skip, skip+paging);

const rest = objects.length % paging;
Expand Down Expand Up @@ -316,7 +312,6 @@ const defaultConfig = {
toolbar: ToolbarDefault,
showToolbar: true,
showColumnsWithoutConfig: true, //show all columns which are not explicitly hidden
paging: DEFAULT_ITEMS_PER_PAGE,
sortValueGetter: ({value}) => {
if (value){
const valueType = typeof value;
Expand Down
23 changes: 22 additions & 1 deletion lib/Pager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, { Component, PropTypes } from 'react';
import Pagination from 'react-bootstrap/lib/Pagination';
import Glyphicon from 'react-bootstrap/lib/Glyphicon';

import { DEFAULT_ITEMS_PER_PAGE } from './constants';

class Pager extends Component {
constructor(props){
super(props);
Expand Down Expand Up @@ -43,8 +45,27 @@ if (process.env.NODE_ENV !== 'production'){
Pager.propTypes = {
currentPage : PropTypes.number.isRequired,
numberOfPages : PropTypes.number.isRequired,
onChange : PropTypes.func.isRequired
onChange : PropTypes.func.isRequired,
rowsPerPage : (props, propName, componentName) => {
const raw = props[propName];
if (raw === undefined){
return new Error(
'Required prop `' + propName + '` was not specified in `' + componentName + '`.'
);
}
const value = Number(raw);
if (Number.isNaN(value) || value < 1) {
return new Error(
'Invalid prop `' + propName + '`=`'+raw+'` supplied to' +
' `' + componentName + '`. Only positive numbers (>0) are accepted'
);
}
}
};
}

Pager.defaultProps = {
rowsPerPage : DEFAULT_ITEMS_PER_PAGE
};

export default Pager;

0 comments on commit e4c9b9d

Please sign in to comment.