mirror of
https://github.com/gosticks/react-table.git
synced 2026-08-13 21:40:17 +00:00
Always keep track of internal state regardless of controlled props, but allow prop overrides
This commit is contained in:
+8
-3
@@ -4510,6 +4510,10 @@ react-dom@^15.5.4:
|
||||
object-assign "^4.1.0"
|
||||
prop-types "~15.5.7"
|
||||
|
||||
react-fastclick@^3.0.1:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/react-fastclick/-/react-fastclick-3.0.1.tgz#e438f9a63cad77c0bb61bb7fa4fd6668451ed83d"
|
||||
|
||||
react-html-attributes@^1.3.0:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/react-html-attributes/-/react-html-attributes-1.3.0.tgz#c97896e9cac47ad9c4e6618b835029a826f5d28c"
|
||||
@@ -4580,15 +4584,16 @@ react-scripts@0.9.5:
|
||||
optionalDependencies:
|
||||
fsevents "1.0.17"
|
||||
|
||||
react-story@^0.0.3:
|
||||
version "0.0.3"
|
||||
resolved "https://registry.yarnpkg.com/react-story/-/react-story-0.0.3.tgz#abb01ddff286466f99f47764d422b1488a656ab3"
|
||||
react-story@^0.0.6:
|
||||
version "0.0.6"
|
||||
resolved "https://registry.yarnpkg.com/react-story/-/react-story-0.0.6.tgz#ec3e6b42e5edab8a74dd581c12bd321ec304eaba"
|
||||
dependencies:
|
||||
classnames "^2.2.5"
|
||||
glamor "^2.20.25"
|
||||
glamorous "^3.14.0"
|
||||
javascript-detect-element-resize "^0.5.3"
|
||||
raf "^3.3.2"
|
||||
react-fastclick "^3.0.1"
|
||||
react-router-dom next
|
||||
|
||||
react@^15.5.4:
|
||||
|
||||
+3
-7
@@ -509,15 +509,11 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
|
||||
} else {
|
||||
newExpanded = _.set(newExpanded, cellInfo.nestingPath, {})
|
||||
}
|
||||
if (onExpandedChange) {
|
||||
onExpandedChange(newExpanded, cellInfo.nestingPath, e)
|
||||
}
|
||||
// If expanded is being controlled, don't manage internal state
|
||||
if (this.props.expanded) {
|
||||
return
|
||||
}
|
||||
|
||||
return this.setStateWithData({
|
||||
expanded: newExpanded
|
||||
}, () => {
|
||||
onExpandedChange && onExpandedChange(newExpanded, cellInfo.nestingPath, e)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+8
-32
@@ -403,17 +403,13 @@ export default Base => class extends Base {
|
||||
// User actions
|
||||
onPageChange (page) {
|
||||
const {onPageChange, collapseOnPageChange} = this.props
|
||||
onPageChange && onPageChange(page)
|
||||
// If controlled, do not keep track of state
|
||||
if (typeof this.props.page !== 'undefined') {
|
||||
this.fireFetchData()
|
||||
return
|
||||
}
|
||||
|
||||
const newState = {page}
|
||||
if (collapseOnPageChange) {
|
||||
newState.expanded = {}
|
||||
}
|
||||
this.setStateWithData(newState, () => {
|
||||
onPageChange && onPageChange(page)
|
||||
this.fireFetchData()
|
||||
})
|
||||
}
|
||||
@@ -426,16 +422,11 @@ export default Base => class extends Base {
|
||||
const currentRow = pageSize * page
|
||||
const newPage = Math.floor(currentRow / newPageSize)
|
||||
|
||||
onPageSizeChange && onPageSizeChange(newPageSize, newPage)
|
||||
if (typeof this.props.page !== 'undefined') {
|
||||
this.fireFetchData()
|
||||
return
|
||||
}
|
||||
|
||||
this.setStateWithData({
|
||||
pageSize: newPageSize,
|
||||
page: newPage
|
||||
}, () => {
|
||||
onPageSizeChange && onPageSizeChange(newPageSize, newPage)
|
||||
this.fireFetchData()
|
||||
})
|
||||
}
|
||||
@@ -528,16 +519,12 @@ export default Base => class extends Base {
|
||||
}
|
||||
}
|
||||
}
|
||||
// If controlled, do not keep track of state
|
||||
onSortedChange && onSortedChange(newSorted, column, additive)
|
||||
if (typeof this.props.sorted !== 'undefined') {
|
||||
this.fireFetchData()
|
||||
return
|
||||
}
|
||||
|
||||
this.setStateWithData({
|
||||
page: ((!sorted.length && newSorted.length) || !additive) ? 0 : this.state.page,
|
||||
sorted: newSorted
|
||||
}, () => {
|
||||
onSortedChange && onSortedChange(newSorted, column, additive)
|
||||
this.fireFetchData()
|
||||
})
|
||||
}
|
||||
@@ -560,17 +547,10 @@ export default Base => class extends Base {
|
||||
})
|
||||
}
|
||||
|
||||
onFilteredChange && onFilteredChange(newFiltering, column, value)
|
||||
|
||||
// If filters is being controlled, do not manage state internally
|
||||
if (this.props.filtered) {
|
||||
this.fireFetchData()
|
||||
return
|
||||
}
|
||||
|
||||
this.setStateWithData({
|
||||
filtered: newFiltering
|
||||
}, () => {
|
||||
onFilteredChange && onFilteredChange(newFiltering, column, value)
|
||||
this.fireFetchData()
|
||||
})
|
||||
}
|
||||
@@ -653,14 +633,10 @@ export default Base => class extends Base {
|
||||
value: newWidth
|
||||
})
|
||||
|
||||
onResizedChange && onResizedChange(newResized, event)
|
||||
|
||||
if (this.props.resized) {
|
||||
return
|
||||
}
|
||||
|
||||
this.setStateWithData({
|
||||
resized: newResized
|
||||
}, () => {
|
||||
onResizedChange && onResizedChange(newResized, event)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user