-
Notifications
You must be signed in to change notification settings - Fork 380
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
feat(react-grid): Ability to show all rows on a page via page size selector #150
Merged
SergeyAlexeev
merged 19 commits into
DevExpress:master
from
SergeyAlexeev:select-all-pages
Jun 21, 2017
Merged
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a17b457
The 'all' key as allowed page size
SergeyAlexeev d5d6e1f
Merge branch 'master' of https://github.com/DevExpress/devextreme-rea…
SergeyAlexeev 206974c
UI improvements
SergeyAlexeev 3e44ddf
Docs
SergeyAlexeev 8f68556
Some additional fixes
SergeyAlexeev ae44b8f
Extract consts
SergeyAlexeev 600419f
The 'all' key is replaced with 0
SergeyAlexeev d8dcb8b
Some additional fixes
SergeyAlexeev 0742bb6
Small refactoring
SergeyAlexeev 333cad0
Introduce the showAllPagesText option
SergeyAlexeev 38edd54
Docs
SergeyAlexeev 4d768a9
Rename showAllPagesText with showAllText
SergeyAlexeev 777f7d7
Move showAllText to plugin wrappers
SergeyAlexeev 9ebb721
Docs is updated
SergeyAlexeev 4379934
Merge branch 'master' into select-all-pages
SergeyAlexeev 93c4387
Update paging.md
viterobk 6e41a41
Update paging.md
dirk-pieterse 497475c
Update paging-panel.md
dirk-pieterse a4b9a62
Update paging-state.md
dirk-pieterse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 17 additions & 5 deletions
22
packages/dx-react-grid-bootstrap3/src/plugins/paging-panel.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { PagingPanel as PagingPanelBase } from '@devexpress/dx-react-grid'; | ||
import { Pager } from '../templates/pager'; | ||
|
||
const pagerTemplate = props => <Pager {...props} />; | ||
|
||
export const PagingPanel = props => ( | ||
export const PagingPanel = ({ showAllText, ...restProps }) => ( | ||
<PagingPanelBase | ||
pagerTemplate={pagerTemplate} | ||
{...props} | ||
pagerTemplate={ | ||
props => ( | ||
<Pager | ||
showAllText={showAllText} | ||
{...props} | ||
/> | ||
) | ||
} | ||
{...restProps} | ||
/> | ||
); | ||
|
||
PagingPanel.propTypes = { | ||
showAllText: PropTypes.string, | ||
}; | ||
PagingPanel.defaultProps = { | ||
showAllText: undefined, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
packages/dx-react-grid-bootstrap3/src/templates/page-size-selector.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { PageSizeSelector } from './page-size-selector'; | ||
|
||
describe('PageSizeSelector', () => { | ||
describe('#render', () => { | ||
const mountPageSizeSelector = ({ | ||
pageSize, | ||
allowedPageSizes, | ||
showAllText, | ||
onPageSizeChange = () => {}, | ||
}) => mount(<PageSizeSelector | ||
pageSize={pageSize} | ||
allowedPageSizes={allowedPageSizes} | ||
showAllText={showAllText} | ||
onPageSizeChange={onPageSizeChange} | ||
/>); | ||
|
||
it('can show info about page sizes', () => { | ||
const tree = mountPageSizeSelector({ | ||
pageSize: 10, | ||
allowedPageSizes: [5, 10], | ||
}); | ||
|
||
const mobileSelector = tree.find('select'); | ||
const desktopSelector = tree.find('ul.pagination'); | ||
const mobileSelectorItems = mobileSelector.find('option'); | ||
const desktopSelectorItems = desktopSelector.find('li'); | ||
|
||
expect(mobileSelector).toHaveLength(1); | ||
expect(mobileSelector.prop('value')).toBe(10); | ||
expect(mobileSelectorItems).toHaveLength(2); | ||
expect(mobileSelectorItems.at(0).prop('value')).toBe(5); | ||
expect(mobileSelectorItems.at(0).text()).toBe('5'); | ||
expect(mobileSelectorItems.at(1).prop('value')).toBe(10); | ||
expect(mobileSelectorItems.at(1).text()).toBe('10'); | ||
|
||
expect(desktopSelector).toHaveLength(1); | ||
expect(desktopSelectorItems).toHaveLength(2); | ||
expect(desktopSelectorItems.at(0).prop('className')).toBe(''); | ||
expect(desktopSelectorItems.at(0).text()).toBe('5'); | ||
expect(desktopSelectorItems.at(1).prop('className')).toBe('active'); | ||
expect(desktopSelectorItems.at(1).text()).toBe('10'); | ||
}); | ||
|
||
it('can render the \'All\' item', () => { | ||
const tree = mountPageSizeSelector({ | ||
pageSize: 10, | ||
allowedPageSizes: [5, 10, 0], | ||
}); | ||
|
||
const mobileSelector = tree.find('select'); | ||
const desktopSelector = tree.find('ul.pagination'); | ||
const mobileSelectorItems = mobileSelector.find('option'); | ||
const desktopSelectorItems = desktopSelector.find('li'); | ||
|
||
expect(mobileSelectorItems).toHaveLength(3); | ||
expect(mobileSelectorItems.at(2).prop('value')).toBe(0); | ||
expect(mobileSelectorItems.at(2).text()).toBe('All'); | ||
|
||
expect(desktopSelectorItems).toHaveLength(3); | ||
expect(desktopSelectorItems.at(2).text()).toBe('All'); | ||
}); | ||
|
||
it('can customize the \'All\' item text', () => { | ||
const tree = mountPageSizeSelector({ | ||
pageSize: 10, | ||
allowedPageSizes: [5, 10, 0], | ||
showAllText: 'Show all', | ||
}); | ||
|
||
const mobileSelector = tree.find('select'); | ||
const desktopSelector = tree.find('ul.pagination'); | ||
|
||
expect(mobileSelector.find('option').at(2).text()).toBe('Show all'); | ||
expect(desktopSelector.find('li').at(2).text()).toBe('Show all'); | ||
}); | ||
|
||
it('can handle the \'onPageSizeChange\' event', () => { | ||
const onPageSizeChange = jest.fn(); | ||
const tree = mountPageSizeSelector({ | ||
pageSize: 5, | ||
allowedPageSizes: [5, 10], | ||
onPageSizeChange, | ||
}); | ||
|
||
const mobileSelector = tree.find('select'); | ||
const desktopSelector = tree.find('ul.pagination'); | ||
|
||
mobileSelector.simulate('change', { target: { value: 10 } }); | ||
desktopSelector.find('li > a').at(0).simulate('click'); | ||
|
||
expect(onPageSizeChange.mock.calls[0][0]).toBe(10); | ||
expect(onPageSizeChange.mock.calls[1][0]).toBe(5); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why could we not escape earlier? Slicing seems redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slicing is for array copying, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but this copy is needed only for processing listed below in this function. We can return original rows if processing is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, got it.