<Table> using the new stateless <Checkbox>
parent
b1fe6f6e27
commit
b3150f4e74
|
@ -7,23 +7,25 @@ class Head extends React.Component {
|
|||
static propTypes = {
|
||||
className: React.PropTypes.string,
|
||||
model: React.PropTypes.object,
|
||||
onSelect: React.PropTypes.func
|
||||
onSelect: React.PropTypes.func,
|
||||
selected: React.PropTypes.bool
|
||||
};
|
||||
|
||||
static defaultProps = {
|
||||
className: '',
|
||||
model: {}
|
||||
model: {},
|
||||
selected: false
|
||||
};
|
||||
|
||||
handleSelectChange = (event, instance) => {
|
||||
this.props.onSelect(event, instance.getValue());
|
||||
handleSelectChange = (event) => {
|
||||
this.props.onSelect(event);
|
||||
};
|
||||
|
||||
renderCellSelectable () {
|
||||
if (this.props.onSelect) {
|
||||
return (
|
||||
<th className={style.selectable}>
|
||||
<Checkbox onChange={this.handleSelectChange}/>
|
||||
<Checkbox onChange={this.handleSelectChange} checked={this.props.selected}/>
|
||||
</th>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ class Row extends React.Component {
|
|||
this.props.onChange(event, this, key, event.target.value);
|
||||
};
|
||||
|
||||
handleSelectChange = (event, instance) => {
|
||||
this.props.onSelect(event, instance.getValue(), this);
|
||||
handleSelectChange = (event) => {
|
||||
this.props.onSelect(event, this);
|
||||
};
|
||||
|
||||
renderCell (key) {
|
||||
|
|
|
@ -42,10 +42,11 @@ class Table extends React.Component {
|
|||
}
|
||||
};
|
||||
|
||||
handleRowSelect = (event, selected, instance) => {
|
||||
handleRowSelect = (event, instance) => {
|
||||
if (this.props.onSelect) {
|
||||
const selected_rows = this.state.selected_rows;
|
||||
const index = instance.props.index;
|
||||
const selected_rows = this.state.selected_rows;
|
||||
const selected = selected_rows.indexOf(index) === -1;
|
||||
if (selected) {
|
||||
selected_rows.push(index);
|
||||
this.props.onSelect(event, instance.props.data);
|
||||
|
@ -56,8 +57,8 @@ class Table extends React.Component {
|
|||
}
|
||||
};
|
||||
|
||||
handleRowsSelect = (event, selected) => {
|
||||
this.setState({ selected: selected });
|
||||
handleRowsSelect = (event) => {
|
||||
this.setState({ selected: !this.state.selected });
|
||||
};
|
||||
|
||||
isChanged = (data, base) => {
|
||||
|
@ -76,6 +77,7 @@ class Table extends React.Component {
|
|||
<Head
|
||||
model={this.props.model}
|
||||
onSelect={this.props.onSelect ? this.handleRowsSelect : null}
|
||||
selected={this.state.selected}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue