fix: table defaultChecked not work

pull/77/merge
tjz 2018-06-08 22:30:25 +08:00
parent dc0f0b967c
commit ec1999dea4
4 changed files with 11 additions and 12 deletions

View File

@ -11,7 +11,7 @@ export default {
props: SelectionBoxProps,
data () {
return {
sChecked: this.getCheckState(this.$props),
checked: this.getCheckState(this.$props),
}
},
@ -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 })
})
},
@ -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,

View File

@ -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)
)

View File

@ -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]
},
@ -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))
},
@ -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 = []
@ -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
})
@ -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}

View File

@ -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>;
}