Skip to content

Customize labels "Search" and "Page Size" with props. #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/table/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ function buildTable(data) {
initialPageLength={5}
initialSortBy={{ prop: 'city', order: 'descending' }}
pageLengthOptions={[ 5, 20, 50 ]}
searchText='Search Everything'
pageSizeText='Per page'
/>
);
}
Expand Down
7 changes: 4 additions & 3 deletions src/PartialTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export default class PartialTable extends Component {
render() {
const {
onFilter, onPageSizeChange, onPageNumberChange, onSort,
pageLengthOptions, columns, keys, buildRowOptions,
pageLengthOptions, columns, keys, searchText,
pageSizeText, buildRowOptions,
} = this.props;

const {
Expand All @@ -20,7 +21,7 @@ export default class PartialTable extends Component {
<div className="row">
<div className="col-xs-4">
<div>
<label htmlFor="page-menu">Page size:</label>
<label htmlFor="page-menu">{pageSizeText}:</label>
<select
id="page-menu"
value={pageSize}
Expand All @@ -34,7 +35,7 @@ export default class PartialTable extends Component {
</select>
</div>
<div>
<label htmlFor="search-field">Search:</label>
<label htmlFor="search-field">{searchText}:</label>
<input
id="search-field"
type="search"
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/dataReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ describe('dataReducer', () => {
pageNumber: 0,
pageSize: 5,
totalPages: 1,
searchText: 'Search',
pageSizeText: 'Page size',
};

expect(dataReducer(undefined, action)).toEqual(expected);
Expand Down
2 changes: 2 additions & 0 deletions src/dataReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const initialState: State = {
sortBy: null,
pageNumber: 0,
pageSize: 5,
searchText: 'Search',
pageSizeText: 'Page size',
};

function calculatePage(data, pageSize, pageNumber) {
Expand Down
4 changes: 4 additions & 0 deletions src/enhanceDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type Props = {
keys: Array<string>;
buildRowOptions: any;
filters: any;
searchText: string;
pageSizeText: string;
};

const mapPropsToState = (props) => ({
Expand All @@ -30,6 +32,8 @@ export default function enhanceDataTable(ComposedComponent) {
filters: {
globalSearch: { filter: containsIgnoreCase },
},
searchText: 'Search',
pageSizeText: 'Page size',
};

constructor(props: Props) {
Expand Down
2 changes: 2 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export type State = {
pageSize: number;
pageNumber: number;
totalPages: number;
searchText: string;
pageSizeText: string;
filterValues: {
[key: string]: string;
};
Expand Down