选中行。

This commit is contained in:
tengge1 2019-09-19 20:46:52 +08:00
parent ab477fa0d0
commit b7dc3bd2b1
2 changed files with 14 additions and 4 deletions

View File

@ -15,17 +15,21 @@ class RoleManageWindow extends React.Component {
pageSize: 20,
pageNum: 1,
total: 0,
selected: null,
};
this.update = this.update.bind(this);
this.handleAdd = this.handleAdd.bind(this);
this.handleEdit = this.handleEdit.bind(this);
this.renderStatus = this.renderStatus.bind(this);
this.handleClose = this.handleClose.bind(this);
this.renderStatus = this.renderStatus.bind(this);
this.handleSelect = this.handleSelect.bind(this);
}
render() {
const { data, pageSize, pageNum, total } = this.state;
const { data, pageSize, pageNum, total, selected } = this.state;
return <Window
className={'RoleManageWindow'}
@ -37,7 +41,7 @@ class RoleManageWindow extends React.Component {
<Toolbar>
<Button onClick={this.handleAdd}>{_t('Create')}</Button>
</Toolbar>
<DataGrid data={data} pageSize={pageSize} pageNum={pageNum} total={total} keyField={'ID'}>
<DataGrid data={data} pageSize={pageSize} pageNum={pageNum} total={total} selected={selected} onSelect={this.handleSelect} keyField={'ID'}>
<Columns>
<Column type={'number'} title={'#'}></Column>
<Column field={'Name'} title={_t('Name')}></Column>
@ -84,6 +88,12 @@ class RoleManageWindow extends React.Component {
renderStatus(value) {
return value === 0 ? '启用' : '禁用';
}
handleSelect(selected) {
this.setState({
selected: selected.ID,
});
}
}
export default RoleManageWindow;

View File

@ -61,7 +61,7 @@ class DataGrid extends React.Component {
}
handleClick(onSelect, event) {
const keyField = this.props;
const keyField = this.props.keyField;
const id = event.currentTarget.getAttribute('data-id');
const record = this.props.data.filter(n => n[keyField] === id)[0];