Skip to content

Commit

Permalink
fix: table defaultChecked not work
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Jun 8, 2018
1 parent dc0f0b9 commit ec1999d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
8 changes: 4 additions & 4 deletions components/table/SelectionBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
props: SelectionBoxProps,
data () {
return {
sChecked: this.getCheckState(this.$props),
checked: this.getCheckState(this.$props),
}
},

Expand All @@ -28,8 +28,8 @@ export default {
subscribe () {
const { store } = this
this.unsubscribe = store.subscribe(() => {
const sChecked = this.getCheckState(this.$props)
this.setState({ sChecked })
const checked = this.getCheckState(this.$props)
this.setState({ checked })
})
},

Expand All @@ -48,7 +48,7 @@ export default {

render () {
const { type, rowIndex, ...rest } = getOptionProps(this)
const { sChecked: checked, $attrs, $listeners } = this
const { checked, $attrs, $listeners } = this
const checkboxProps = {
props: {
checked,
Expand Down
2 changes: 1 addition & 1 deletion components/table/SelectionCheckboxAll.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default {
if (type === 'every' || type === 'some') {
return (
byDefaultChecked
? data[type]((item, i) => getCheckboxPropsByItem(item, i).defaultChecked)
? data[type]((item, i) => getCheckboxPropsByItem(item, i).props.defaultChecked)
: data[type]((item, i) =>
store.getState().selectedRowKeys.indexOf(getRecordKey(item, i)) >= 0)
)
Expand Down
11 changes: 6 additions & 5 deletions components/table/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,14 @@ export default {
getCheckboxPropsByItem (item, index) {
const { rowSelection = {}} = this
if (!rowSelection.getCheckboxProps) {
return {}
return { props: {}}
}
const key = this.getRecordKey(item, index)
// Cache checkboxProps
if (!this.CheckboxPropsCache[key]) {
this.CheckboxPropsCache[key] = rowSelection.getCheckboxProps(item)
}
this.CheckboxPropsCache[key].props = this.CheckboxPropsCache[key].props || {}
return this.CheckboxPropsCache[key]
},

Expand All @@ -166,7 +167,7 @@ export default {
return []
}
return this.getFlatData()
.filter((item, rowIndex) => this.getCheckboxPropsByItem(item, rowIndex).defaultChecked)
.filter((item, rowIndex) => this.getCheckboxPropsByItem(item, rowIndex).props.defaultChecked)
.map((record, rowIndex) => this.getRecordKey(record, rowIndex))
},

Expand Down Expand Up @@ -449,7 +450,7 @@ export default {
const defaultSelection = this.store.getState().selectionDirty ? [] : this.getDefaultSelection()
const selectedRowKeys = this.store.getState().selectedRowKeys.concat(defaultSelection)
const changeableRowKeys = data
.filter((item, i) => !this.getCheckboxPropsByItem(item, i).disabled)
.filter((item, i) => !this.getCheckboxPropsByItem(item, i).props.disabled)
.map((item, i) => this.getRecordKey(item, i))

const changeRowKeys = []
Expand Down Expand Up @@ -595,7 +596,7 @@ export default {
if (rowSelection) {
const data = this.getFlatCurrentPageData().filter((item, index) => {
if (rowSelection.getCheckboxProps) {
return !this.getCheckboxPropsByItem(item, index).disabled
return !this.getCheckboxPropsByItem(item, index).props.disabled
}
return true
})
Expand All @@ -610,7 +611,7 @@ export default {
width: rowSelection.columnWidth,
}
if (rowSelection.type !== 'radio') {
const checkboxAllDisabled = data.every((item, index) => this.getCheckboxPropsByItem(item, index).disabled)
const checkboxAllDisabled = data.every((item, index) => this.getCheckboxPropsByItem(item, index).props.disabled)
selectionColumn.title = (
<SelectionCheckboxAll
store={this.store}
Expand Down
2 changes: 0 additions & 2 deletions components/table/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ export const SelectionBoxProps = {
name: PropTypes.string,
disabled: PropTypes.bool,
id: PropTypes.string,
defaultChecked: PropTypes.bool,
checked: PropTypes.bool,
// onChange: React.ChangeEventHandler<HTMLInputElement>;
}

Expand Down

0 comments on commit ec1999d

Please sign in to comment.