我正在尝试向固定数据表中的每一行添加按钮,但我不知道如何。我目前的代码:
var Details = React.createClass({
getInitialState() {
return {
rows: usersStore.getUsersList(),
filteredRows: null,
filterBy: null,
};
},
componentWillMount() {
this._filterRowsBy(this.state.filterBy);
},
_rowGetter(rowIndex) {
return this.state.filteredRows[rowIndex];
},
_filterRowsBy(filterBy) {
var rows = this.state.rows.slice();
var filteredRows = filterBy ? rows.filter(function(row){
return row.name.toLowerCase().indexOf(filterBy.toLowerCase()) >= 0
}) : rows;
this.setState({
filteredRows,
filterBy,
});
},
_onFilterChange(e) {
this._filterRowsBy(e.target.value);
},
render: function () {
return (
<div>
<label>filter by <input onChange={this._onFilterChange} /></label>
<Table
height={200}
rowHeight={30}
rowGetter={this._rowGetter}
rowsCount={this.state.filteredRows.length}
width={450}
maxHeight={450}
headerHeight={40}>
<Column
label="Name"
width={270}
dataKey="name"
/>
<Column
label="Age"
width={100}
dataKey="age"
/>
<Column
label="Qualification"
width={120}
dataKey="Qualification"
/>
<Column label="Edit"
width={120}>
<button type="button" className="btn btn-default" onClick={this.update}>Update</button>
</Column>
</Table>
</div>
);
}
})
使用此代码时,它显示数据键是强制性的,如果我删除列标签并仅在表中添加按钮,它也不接受。