Skip to content

Commit 95fe97d

Browse files
refactor(react-grid): remove totalCount property from PagingState to CustomPaging (#555)
BREAKING CHANGES: We have moved the PagingState plugin's `totalCount` property to the CustomPaging plugin to improve API consistency. Now, you can add the CustomPaging plugin to a project and specify its `totalCount` property to implement remote paging. Before: ```js <Grid> <...> <PagingState totalCount={10} /> </Grid> ``` After: ```js <Grid> <...> <PagingState /> <CustomPaging totalCount={10} /> </Grid> ```
1 parent 16eb588 commit 95fe97d

File tree

13 files changed

+122
-46
lines changed

13 files changed

+122
-46
lines changed

packages/dx-react-demos/src/bootstrap3/featured-remote-data/demo.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
33
import {
44
PagingState,
55
SortingState,
6+
CustomPaging,
67
} from '@devexpress/dx-react-grid';
78
import {
89
Grid,
@@ -151,6 +152,8 @@ export default class Demo extends React.PureComponent {
151152
onCurrentPageChange={this.changeCurrentPage}
152153
pageSize={pageSize}
153154
onPageSizeChange={this.changePageSize}
155+
/>
156+
<CustomPaging
154157
totalCount={totalCount}
155158
/>
156159
<Table

packages/dx-react-demos/src/bootstrap3/paging/remote-paging.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import {
33
PagingState,
4+
CustomPaging,
45
} from '@devexpress/dx-react-grid';
56
import {
67
Grid,
@@ -84,6 +85,8 @@ export default class Demo extends React.PureComponent {
8485
currentPage={currentPage}
8586
onCurrentPageChange={this.changeCurrentPage}
8687
pageSize={pageSize}
88+
/>
89+
<CustomPaging
8790
totalCount={totalCount}
8891
/>
8992
<Table />

packages/dx-react-demos/src/material-ui/featured-remote-data/demo.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
33
import {
44
PagingState,
55
SortingState,
6+
CustomPaging,
67
} from '@devexpress/dx-react-grid';
78
import {
89
Grid,
@@ -161,6 +162,8 @@ export default class Demo extends React.PureComponent {
161162
onCurrentPageChange={this.changeCurrentPage}
162163
pageSize={pageSize}
163164
onPageSizeChange={this.changePageSize}
165+
/>
166+
<CustomPaging
164167
totalCount={totalCount}
165168
/>
166169
<Table

packages/dx-react-demos/src/material-ui/paging/remote-paging.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import {
33
PagingState,
4+
CustomPaging,
45
} from '@devexpress/dx-react-grid';
56
import {
67
Grid,
@@ -84,6 +85,8 @@ export default class Demo extends React.PureComponent {
8485
currentPage={currentPage}
8586
onCurrentPageChange={this.changeCurrentPage}
8687
pageSize={pageSize}
88+
/>
89+
<CustomPaging
8790
totalCount={totalCount}
8891
/>
8992
<Table />

packages/dx-react-grid/docs/guides/paging.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,35 @@ The Grid component supports data paging. You can specify the page size and switc
77
The following plugins implement filtering features:
88

99
- [PagingState](../reference/paging-state.md) - controls the paging state
10+
- [CustomPaging](../reference/custom-paging.md) - allows implementing a custom totalCount calculation logic
1011
- [IntegratedPaging](../reference/integrated-paging.md) - performs built-in data paging
1112
- [PagingPanel](../reference/paging-panel.md) - renders the Paging Panel
1213

1314
Note that the [plugin order](./plugin-overview.md#plugin-order) is important.
1415

1516
## Basic Paging Setup
1617

17-
Import the plugins listed above to set up a Grid with basic paging.
18+
Use the `PagingState`, `LocalPaging` (or `CustomPaging`), and `PagingPanel` plugins to set up a Grid with paging.
1819

1920
## Uncontrolled Mode
2021

21-
In the [uncontrolled mode](controlled-and-uncontrolled-modes.md), specify the initial active page index in the `PagingState` plugin's `defaultCurrentPage` property.
22+
In [uncontrolled mode](controlled-and-uncontrolled-modes.md), specify the initial active page index in the `PagingState` plugin's `defaultCurrentPage` property.
2223

23-
In the following example, the page size is specified using the `PagingState` plugin's `pageSize` property, which is usual for the controlled mode. However, the `onPageSizeChange` event handler is not specified because page size is not supposed to be changed internally as the Page Size Selector is not available.
24+
In the following example, the page size is specified using the `PagingState` plugin's `pageSize` property, which is usual for the controlled mode. However, the `onPageSizeChange` event handler is not specified because the page size is not supposed to be changed internally as the Page Size Selector is not available.
2425

2526
.embedded-demo(paging/uncontrolled-mode)
2627

2728
## Page Size Selection
2829

2930
Assign an array of available page sizes to the `PagingPanel` plugin's `pageSizes` property to enable page size selection via the UI. The Page Size Selector displays the 'All' item if the specified array contains an item whose value is 0. You can specify custom text for this Page Size Selector item using the `messages.showAll` property.
3031

31-
The example below demonstrates the basic configuration for the uncontrolled mode. The `PagingState` plugin's `defaultPageSize` property defines the initial page size.
32+
The example below demonstrates a basic configuration for the uncontrolled mode. The `PagingState` plugin's `defaultPageSize` property defines the initial page size.
3233

3334
.embedded-demo(paging/page-size-selector)
3435

3536
## Controlled Mode
3637

37-
In the [controlled mode](controlled-and-uncontrolled-modes.md), specify the following `PagingState` plugin property pairs to set a state value and handle its changes:
38+
In [controlled mode](controlled-and-uncontrolled-modes.md), specify the following `PagingState` plugin property pairs to set a state value and handle its changes:
3839

3940
- `currentPage` and `onCurrentPageChange` - the currently displayed page's index
4041
- `pageSize` and `onPageSizeChange` - the page size
@@ -45,14 +46,14 @@ Note that the `onPageSizeChange` handler makes sense only if the `pageSizes` opt
4546

4647
## Remote Paging
4748

48-
You can handle the Grid's paging state changes to request a page data from the server according to the current page index and page size if your data service supports paging.
49+
You can handle the Grid's paging state changes to request page data from the server according to the current page index and the page size if your data service supports paging.
4950

50-
Paging options are updated once an end-user interacts with Paging Panel controls. Handle paging option changes using the `PagingState` plugin's `onCurrentPageChange` and `onPageSizeChange` events and request data from the server using the applied paging options. Once the page data is received from the server, pass it to the `Grid` component's `rows` property.
51+
Paging options are updated once an end-user interacts with Paging Panel controls. Handle paging option changes using the `PagingState` plugin's `onCurrentPageChange` and `onPageSizeChange` events, and request data from the server using the applied paging options. Once the page data is received from the server, pass it to the `Grid` component's `rows` property.
5152

52-
Note that in the case of remote paging, you do not need to use the `IntegratedPaging` plugin.
53+
For remote paging, use the `CustomPaging` plugin instead of the `IntegratedPaging` plugin.
5354

5455
.embedded-demo(paging/remote-paging)
5556

5657
## Using Paging with Other Data Processing Plugins
5758

58-
When you use paging features with sorting, grouping, or filtering, take a note of the order in which the plugins appear in the Grid's container. You need to choose whether to paginate filtered rows or filter the current page. In the first case, put the `IntegratedFiltering` plugin before the `IntegratedPaging` one. Otherwise, inverse the plugins' order.
59+
When you use paging features with sorting, grouping, or filtering, take note of the order in which the plugins appear in the Grid's container. You need to choose whether to paginate filtered rows or filter the current page. In the former case, put the `IntegratedFiltering` plugin before the `IntegratedPaging` one. Otherwise, inverse the plugins' order.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# CustomPaging Plugin Reference
2+
3+
A plugin that allows implementing a custom totalCount calculation logic.
4+
5+
## User Reference
6+
7+
### Dependencies
8+
9+
- [PagingState](paging-state.md)
10+
11+
### Properties
12+
13+
Name | Type | Default | Description
14+
-----|------|---------|------------
15+
totalCount | number | 0 | The total row count.
16+
17+
## Plugin Developer Reference
18+
19+
### Imports
20+
21+
none
22+
23+
### Exports
24+
25+
Name | Plugin | Type | Description
26+
-----|--------|------|------------
27+
totalCount | Getter | number | The total row count.

packages/dx-react-grid/docs/reference/paging-state.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ none
1313
Name | Type | Default | Description
1414
-----|------|---------|------------
1515
currentPage | number | | Specifies the current page number.
16-
defaultCurrentPage | number | 0 | Specifies the initial page in the uncontrolled mode.
16+
defaultCurrentPage | number | 0 | Specifies the initial page in uncontrolled mode.
1717
onCurrentPageChange | (currentPage: number) => void | | Handles current page changes.
1818
pageSize | number | | Specifies the page size. Set this property to `0` to show all rows on a page.
19-
defaultPageSize | number | 10 | Specifies the initial page size in the uncontrolled mode.
19+
defaultPageSize | number | 10 | Specifies the initial page size in uncontrolled mode.
2020
onPageSizeChange | (pageSize: number) => void | | Handles page size changes.
21-
totalCount | number | 0 | Specifies the total row count.
2221

2322
## Plugin Developer Reference
2423

@@ -34,4 +33,3 @@ pageSize | Getter | number | The page size.
3433
setPageSize | Action | (size: number) => void | Changes the page size.
3534
currentPage | Getter | number | The current page number.
3635
setCurrentPage | Action | (page: number) => void | Changes the current page number.
37-
totalCount | Getter | number | The total row count.

packages/dx-react-grid/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export { EditingState } from './plugins/editing-state';
88

99
export { PagingState } from './plugins/paging-state';
1010
export { IntegratedPaging } from './plugins/integrated-paging';
11+
export { CustomPaging } from './plugins/custom-paging';
1112

1213
export { GroupingState } from './plugins/grouping-state';
1314
export { IntegratedGrouping } from './plugins/integrated-grouping';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { Getter, PluginContainer } from '@devexpress/dx-react-core';
4+
5+
const pluginDependencies = [
6+
{ pluginName: 'PagingState' },
7+
];
8+
9+
export class CustomPaging extends React.PureComponent {
10+
render() {
11+
const { totalCount } = this.props;
12+
13+
return (
14+
<PluginContainer
15+
pluginName="CustomPaging"
16+
dependencies={pluginDependencies}
17+
>
18+
<Getter name="totalCount" value={totalCount} />
19+
</PluginContainer>
20+
);
21+
}
22+
}
23+
24+
CustomPaging.propTypes = {
25+
totalCount: PropTypes.number,
26+
};
27+
28+
CustomPaging.defaultProps = {
29+
totalCount: 0,
30+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
import { mount } from 'enzyme';
3+
import { PluginHost } from '@devexpress/dx-react-core';
4+
import { CustomPaging } from './custom-paging';
5+
import { pluginDepsToComponents, getComputedState } from './test-utils';
6+
7+
const defaultDeps = {
8+
plugins: ['PagingState'],
9+
};
10+
11+
describe('CustomPaging', () => {
12+
it('should provide value from the "totalCount" property', () => {
13+
const tree = mount((
14+
<PluginHost>
15+
{pluginDepsToComponents(defaultDeps)}
16+
<CustomPaging
17+
totalCount={100}
18+
/>
19+
</PluginHost>
20+
));
21+
22+
expect(getComputedState(tree).totalCount)
23+
.toBe(100);
24+
});
25+
26+
it('should provide \'0\' if a value for the "totalCount" property undefined', () => {
27+
const tree = mount((
28+
<PluginHost>
29+
{pluginDepsToComponents(defaultDeps)}
30+
<CustomPaging />
31+
</PluginHost>
32+
));
33+
34+
expect(getComputedState(tree).totalCount)
35+
.toBe(0);
36+
});
37+
});

0 commit comments

Comments
 (0)