Skip to content

Commit 9e95b33

Browse files
committed
Feature: Changing defaultSorting now updates the sorting model
1 parent f296b07 commit 9e95b33

File tree

6 files changed

+17
-12
lines changed

6 files changed

+17
-12
lines changed

docs/iframe.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<body>
1717
<div id="root"></div>
1818
<div id="error-display"></div>
19-
<script src="static/preview.7549a2f8d9b5e6663c7a.bundle.js"></script>
19+
<script src="static/preview.742092f25ec9b6802477.bundle.js"></script>
2020
</body>
2121
</html>
2222

docs/static/preview.7549a2f8d9b5e6663c7a.bundle.js renamed to docs/static/preview.742092f25ec9b6802477.bundle.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/static/preview.7549a2f8d9b5e6663c7a.bundle.js.map renamed to docs/static/preview.742092f25ec9b6802477.bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lifecycle.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default {
2626
},
2727

2828
componentWillMount () {
29-
this.setStateWithData(this.getDataModel())
29+
this.setStateWithData(this.getDataModel(this.getResolvedState()))
3030
},
3131

3232
componentDidMount () {
@@ -37,14 +37,18 @@ export default {
3737
const oldState = this.getResolvedState()
3838
const newState = this.getResolvedState(nextProps, nextState)
3939

40+
if (oldState.defaultSorting !== newState.defaultSorting) {
41+
newState.sorting = newState.defaultSorting
42+
}
43+
4044
// Props that trigger a data update
4145
if (
4246
oldState.data !== newState.data ||
4347
oldState.columns !== newState.columns ||
4448
oldState.pivotBy !== newState.pivotBy ||
4549
oldState.sorting !== newState.sorting
4650
) {
47-
this.setStateWithData(this.getDataModel(nextProps, nextState))
51+
this.setStateWithData(this.getDataModel(newState))
4852
}
4953
},
5054

src/methods.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import _ from './utils'
22

33
export default {
4-
getDataModel (nextProps, nextState) {
4+
getDataModel (newState) {
55
const {
66
columns,
77
pivotBy = [],
@@ -14,7 +14,7 @@ export default {
1414
page,
1515
pages,
1616
pageSize
17-
} = this.getResolvedState(nextProps, nextState)
17+
} = newState
1818

1919
// Determine Header Groups
2020
let hasHeaderGroups = false
@@ -219,6 +219,7 @@ export default {
219219
const newPage = page > newPages ? newPage - 1 : page
220220

221221
return {
222+
...newState,
222223
resolvedData,
223224
pivotColumn,
224225
allVisibleColumns,

stories/ServerSide.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ const ServerSide = React.createClass({
4848
}
4949
},
5050
fetchData (state, instance) {
51-
console.log(state, instance)
5251
// Whenever the table model changes, or the user sorts or changes pages, this method gets called and passed the current table model.
5352
// You can set the `loading` prop of the table to true to use the built-in one or show you're own loading bar if you want.
5453
this.setState({loading: true})
5554
// Request the data however you want. Here, we'll use our mocked service we created earlier
5655
requestData(state.pageSize, state.page, state.sorting)
5756
.then((res) => {
57+
console.log(res.rows)
5858
// Now just get the rows of data to your React Table (and update anything else like total pages or loading)
5959
this.setState({
6060
data: res.rows,

0 commit comments

Comments
 (0)