<Table> using the new stateless <Checkbox>

old
@soyjavi 2015-11-07 09:01:07 +07:00
parent b1fe6f6e27
commit b3150f4e74
3 changed files with 15 additions and 11 deletions

View File

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

View File

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

View File

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