Skip to content

Commit

Permalink
Merge pull request #39 from XiaoMi/table-select
Browse files Browse the repository at this point in the history
修改table多选的bug
  • Loading branch information
sivan authored Dec 12, 2018
2 parents 0b875f0 + fc1723e commit b8a4c20
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 73 deletions.
4 changes: 2 additions & 2 deletions components/table/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Expand extends Component {

export default class Body extends Component {
render () {
let {columns, dataSource, cbs: {addExpand, rowClick}, rowSelection = { }, highlightCols} = this.props
let {columns, dataSource, cbs: {addExpand}, rowSelection = { }, highlightCols} = this.props
let selectedRowKeys = rowSelection.selectedRowKeys || []
// 表头分组
let i = 0
Expand Down Expand Up @@ -88,7 +88,7 @@ export default class Body extends Component {
i++
// 动态插入的组件不累加
}
return <tr onClick={() => rowClick(undefined, item, k)} className={prifix('table-row', selectedRowKeys.includes(item.key) ? 'picked' : null, item.expand ? 'expanded' : null)} key={item.key || 'tr-' + k} >{tr}</tr>
return <tr className={prifix('table-row', selectedRowKeys.includes(item.key) ? 'picked' : null, item.expand ? 'expanded' : null)} key={item.key || 'tr-' + k} >{tr}</tr>
})

return (
Expand Down
74 changes: 4 additions & 70 deletions components/table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import prifix from './prefix'
import Checkbox from '../checkbox'
import Pagination from '../pagination'
import Icon from '../icon'
import '../style'
import './style'
import '../checkbox/style'
import '../pagination/style'
import '../icon/style'
Expand Down Expand Up @@ -190,42 +190,6 @@ export default class Table extends Component {
let obj = dataSource.find(o => o.key === item.key)
obj.ishiuitableopen = !obj.ishiuitableopen
this.setState({dataSource: dataSource, ...columnsDetail})
// let {index, open} = e.target.dataset
// index = parseInt(index)
// open = open === 'true'
//
// let {data} = this.props
// if (!open) {
// data.splice(index + 1, 0, {expand: true, parent: index, ...{width: '50px'}, ...item})
// } else {
// data.splice(index + 1, 1)
// }
// e.target.dataset.open = !open
// this.setState({dataSource: data})
},

rowClick: (text, record, index) => {
// let { rowSelection } = this.props
// let { dataSource } = this.state

// 点击行的时候如果配置了分页
// if (rowSelection) {
// let {selectedRowKeys} = this.state
// let {onChange, getCheckboxProps = (record) => ({ disabled: false, dataName: record.key })} = rowSelection
// let selected = selectedRowKeys.includes(record.key)
// if (getCheckboxProps(record).disabled) {
// return
// }
// if (selected) {
// selectedRowKeys.splice(selectedRowKeys.indexOf(record.key), 1)
// } else {
// selectedRowKeys.push(record.key)
// }
//
// this.setState({selectedRowKeys}, () => {
// onChange(selectedRowKeys, dataSource.filter(item => selectedRowKeys.includes(item.key)))
// })
// }
}
}

Expand All @@ -240,7 +204,6 @@ export default class Table extends Component {
scroll,
columnMenu: false,
// 由外部属性重构为内部状态
selectedRowKeys: [],
leftFiexColumns: [],
rightFixColumns: [],
columns: [],
Expand Down Expand Up @@ -648,30 +611,10 @@ export default class Table extends Component {
let rightFixColumns = []
let [headerColumns, columns] = this.getHeaderGroup(props.columns)
let {rowSelection, scroll, name} = props
let that = this
if (rowSelection) {
let {selectedRowKeys} = this.state
let {selectedRowKeys = []} = rowSelection
let { dataSource } = this.state

// 点击行的时候如果配置了分页
// if (rowSelection) {
// let {selectedRowKeys} = this.state
// let {onChange, getCheckboxProps = (record) => ({ disabled: false, dataName: record.key })} = rowSelection
// let selected = selectedRowKeys.includes(record.key)
// if (getCheckboxProps(record).disabled) {
// return
// }
// if (selected) {
// selectedRowKeys.splice(selectedRowKeys.indexOf(record.key), 1)
// } else {
// selectedRowKeys.push(record.key)
// }
//
// this.setState({selectedRowKeys}, () => {
// onChange(selectedRowKeys, dataSource.filter(item => selectedRowKeys.includes(item.key)))
// })
// }

columns.unshift({
width: '50',
type: 'select',
Expand All @@ -693,12 +636,7 @@ export default class Table extends Component {
selectedRowKeys.splice(0, selectedRowKeys.length)
data.splice(0, data.length)
}

that.setState({
selectedRowKeys
}, () => {
onChange(selectedRowKeys, data)
})
onChange(selectedRowKeys, data)
}}
/>

Expand All @@ -720,11 +658,7 @@ export default class Table extends Component {
selectedRowKeys = selectedRowKeys.filter(key => record.key !== key)
}

that.setState({
selectedRowKeys
}, () => {
onChange(selectedRowKeys, data.filter(record => selectedRowKeys.includes(record.key)))
})
onChange(selectedRowKeys, data.filter(record => selectedRowKeys.includes(record.key)))
}}
disabled={disabled}
key={record.key}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hi-ui/hiui",
"version": "1.1.3",
"version": "1.1.5",
"description": "HIUI for React",
"scripts": {
"test": "node_modules/.bin/standard && node_modules/.bin/stylelint --config .stylelintrc 'components/**/*.scss'",
Expand Down

0 comments on commit b8a4c20

Please sign in to comment.