Reactjs 将CheckboxEditor与react数据网格一起使用
我是React新手,我正在尝试让React数据网格为其中一列显示一个复选框。我已经导入了react数据网格和react数据网格插件,但我不确定如何将所需的道具传递给CheckboxEditorReactjs 将CheckboxEditor与react数据网格一起使用,reactjs,react-data-grid,Reactjs,React Data Grid,我是React新手,我正在尝试让React数据网格为其中一列显示一个复选框。我已经导入了react数据网格和react数据网格插件,但我不确定如何将所需的道具传递给CheckboxEditor import React, {PropTypes} from "react"; import {connect} from "react-redux"; import {bindActionCreators} from "redux"; import * as identityActions from "
import React, {PropTypes} from "react";
import {connect} from "react-redux";
import {bindActionCreators} from "redux";
import * as identityActions from "../../actions/identityActions";
import * as defectViewActions from "../../actions/defectViewActions";
import MultiSelectBox from "../common/MultiSelectBox";
import ReactDataGrid from "react-data-grid";
import Editors from "react-data-grid-addons";
const {CheckboxEditor} = Editors;
class UserProfilePage extends React.Component {
constructor(props, context) {
super(props, context);
this.setReportingArea = this.setReportingArea.bind(this);
this.rowGetter = this.rowGetter.bind(this);
this.onCellChanged = this.onCellChanged.bind(this);
this.state = {
viewColumns: [],
summaryColumns: [],
detailColumns: [],
commentColumns: [],
columns: [
{
key: "Name",
name: "Column",
resizable: false,
width: 200,
editable: false
},
{
key: "SummaryView",
name: "Summary",
resizable: false,
width: 80,
editor: <CheckboxEditor value={this.props.value} column={null} rowIdx={"1"} />
},
{
key: "DetailView",
name: "Detail",
resizable: false,
width: 80,
editable: true,
},
{
key: "CommentView",
name: "Comment",
resizable: false,
width: 80,
editable: true,
}
]
};
}
componentDidMount() {
this.props.defectViewActions.loadViewColumns();
}
componentWillReceiveProps(nextProps) {
if ((!this.props.viewColumns || this.props.viewColumns.length === 0) && (nextProps.viewColumns || nextProps.viewColumns.length > 0)) {
nextProps.viewColumns.forEach(function (col) {
col.SummaryView = false, col.DetailView = false, col.CommentView = false;
switch (col.DefaultView) {
case 1:
col.SummaryView = true;
break;
case 2:
col.DetailView = true;
break;
case 3:
col.CommentView = true;
break;
}
});
this.setState({
viewColumns: nextProps.viewColumns
})
;
}
}
onCellChanged() {
console.log("Cell updated");
}
// -- React Data Grid ----------------------------------------------------------------------------------------------------------
rowGetter(i) {
if (this.state.viewColumns.length > 0) {
return {
value: this.state.viewColumns[i]
};
}
else {
return "";
}
}
// -----------------------------------------------------------------------------------------------------------------------------
setReportingArea(event) {
this.props.actions.setPreferredReportingArea(event.target.value);
}
render() {
return (
<div style={{marginTop: '50px'}}>
<table className="table table-condensed" style={{width: '70%', margin: 'auto'}}>
<thead>
<tr>
<th colSpan="3"><h2>User Profile</h2></th>
</tr>
</thead>
<tbody>
<tr>
<td>Name:</td>
<td>{this.props.user.name}</td>
</tr>
<tr>
<td>Email:</td>
<td>
{this.props.user.Username}
</td>
</tr>
<tr>
<td>Preferred Reporting Area:</td>
<td>
{(this.props.user.ReportingArea) ? (
<MultiSelectBox name="ddlReportingArea"
onChange={this.setReportingArea}
value={this.props.user.ReportingAreaId}
options={this.props.user.ReportingAreas.map((ra) => {
return {id: ra.Id, value: ra.ReportingAreaName};
}).sort((a, b) => {
return a.value > b.value;
})}/>)
: "None Assigned"}
</td>
</tr>
</tbody>
</table>
<div className="row" style={{width: '70%', margin: 'auto'}}>
<div className="form-horizontal form-group">
<label className="col-md-2 control-label">View:</label>
<div className="col-md-2">
<select className="form-control">
<option>Default</option>
</select>
</div>
</div>
</div>
<div className="row" style={{width: '70%', margin: 'auto'}}>
<div className="col-md-6">
<h4>Available Columns</h4>
<ReactDataGrid
rowHeight={35}
minHeight={500}
minWidth={450}
maxWidth={450}
columns={this.state.columns}
rowGetter={this.rowGetter}
rowsCount={this.state.viewColumns.length}/>
</div>
<div className="col-md-2">
<h4>Default Columns</h4>
</div>
<div className="col-md-2">
<h4>Detail Columns</h4>
</div>
<div className="col-md-2">
<h4>History Columns</h4>
</div>
</div>
</div>
);
}
}
UserProfilePage.propTypes = {
user: PropTypes.object.isRequired,
viewColumns: PropTypes.array.isRequired,
defectViewActions: PropTypes.object.isRequired,
actions: PropTypes.object.isRequired
};
function mapStoreStateToProps(state, ownProps) {
return {
user: state.Identity,
viewColumns: state.ViewColumns
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(identityActions, dispatch),
defectViewActions: bindActionCreators(defectViewActions, dispatch)
};
}
export default connect(mapStoreStateToProps, mapDispatchToProps)(UserProfilePage);
import React,{PropTypes}来自“React”;
从“react redux”导入{connect};
从“redux”导入{bindActionCreators};
从“../../actions/identityActions”导入*作为标识操作;
从“../../actions/defectViewActions”导入*作为defectViewActions;
从“./common/MultiSelectBox”导入MultiSelectBox;
从“react数据网格”导入ReactDataGrid;
从“react数据网格插件”导入编辑器;
const{CheckboxEditor}=编辑器;
类UserProfilePage扩展了React.Component{
构造函数(道具、上下文){
超级(道具、背景);
this.setReportingArea=this.setReportingArea.bind(this);
this.rowGetter=this.rowGetter.bind(this);
this.onCellChanged=this.onCellChanged.bind(this);
此.state={
视图列:[],
汇总列:[],
详细信息列:[],
评论栏:[],
栏目:[
{
键:“名称”,
名称:“列”,
可调整大小:false,
宽度:200,
可编辑:false
},
{
键:“SummaryView”,
名称:“摘要”,
可调整大小:false,
宽度:80,
编辑:
},
{
键:“详细视图”,
名称:“详情”,
可调整大小:false,
宽度:80,
是的,
},
{
键:“评论视图”,
名称:“评论”,
可调整大小:false,
宽度:80,
是的,
}
]
};
}
componentDidMount(){
this.props.defectViewActions.loadViewColumns();
}
组件将接收道具(下一步){
如果(!this.props.viewColumns | | this.props.viewColumns.length==0)和&(nextrops.viewColumns | | nextrops.viewColumns.length>0)){
nextProps.viewColumns.forEach(函数(col){
col.SummaryView=false,col.DetailView=false,col.CommentView=false;
开关(col.DefaultView){
案例1:
col.SummaryView=true;
打破
案例2:
col.DetailView=true;
打破
案例3:
col.CommentView=true;
打破
}
});
这是我的国家({
viewColumns:nextrops.viewColumns
})
;
}
}
onCellChanged(){
控制台日志(“单元更新”);
}
//--反应数据网格----------------------------------------------------------------------------------------------------------
罗格特(一){
如果(this.state.viewColumns.length>0){
返回{
值:this.state.viewColumns[i]
};
}
否则{
返回“”;
}
}
// -----------------------------------------------------------------------------------------------------------------------------
设置报告区域(事件){
this.props.actions.setPreferredReportingArea(event.target.value);
}
render(){
返回(
用户配置文件
姓名:
{this.props.user.name}
电邮:
{this.props.user.Username}
首选报告领域:
{(this.props.user.ReportingArea)(
{
返回{id:ra.id,值:ra.ReportingAreaName};
}).排序((a,b)=>{
返回a.value>b.value;
})}/>)
:“未分配”}
视图:
违约
可用列
默认列
详图柱
历史专栏
);
}
}
UserProfilePage.propTypes={
用户:PropTypes.object.isRequired,
viewColumns:PropTypes.array.isRequired,
defectViewActions:PropTypes.object.isRequired,
操作:PropTypes.object.isRequired
};
函数mapStoreStateToProps(状态,ownProps){
返回{
用户:state.Identity,
viewColumns:state.viewColumns
};
}
功能图DispatchToprops(调度){
返回{
操作:bindActionCreators(标识操作、调度),
defectViewActions:bindActionCreators(