项目作者: hexson

项目描述 :
table editer component for React
高级语言: JavaScript
项目地址: git://github.com/hexson/table-editer.git
创建时间: 2018-04-04T09:00:57Z
项目社区:https://github.com/hexson/table-editer

开源协议:

下载


table-editer

table editer component for React

代码地址

代码地址 -> 传送门

依赖加载

  1. npm install react-handsontable --save

使用

复制./src/TableEditer.js以及TableEditer.css到你的开发(组件)目录下

直接上代码:

  1. import React, { Component } from 'react';
  2. import TableEditer from './TableEditer'; // 这里换成你的本地目录结构
  3. import './App.css';
  4. class Create extends Component {
  5. constructor() {
  6. super(...arguments);
  7. this.state = {
  8. menus: [
  9. {
  10. value: '姓名',
  11. required: true
  12. },
  13. {
  14. value: '结算方式'
  15. },
  16. {
  17. value: '工资',
  18. required: true
  19. },
  20. {
  21. value: '不导入'
  22. }
  23. ],
  24. matchs: ['不导入', '不导入', '不导入'],
  25. data: this.data
  26. };
  27. }
  28. data = [
  29. ['姓名', '结算方式', '工资'],
  30. [],
  31. ['张三', '月结', 6000],
  32. ['李四', '月结', 7500],
  33. ['王五', '月结', 7000],
  34. ['张三', '月结', 6000],
  35. ['李四', '月结', 7000],
  36. ['王五', '月结', 7000]
  37. ]
  38. updateMatchs(matchs) {
  39. this.setState({
  40. matchs
  41. })
  42. }
  43. render() {
  44. return (
  45. <div>
  46. <TableEditer root="hot" data={this.data} menus={this.state.menus} matchs={this.state.matchs} updateMatchs={this.updateMatchs.bind(this)} ></TableEditer>
  47. <br />
  48. <button onClick={() => {this.setState({data: this.data})}}>显示更改后的表格数据</button>
  49. <div>{JSON.stringify(this.state.data)}</div>
  50. <br />
  51. <div>{JSON.stringify(this.state.matchs)}</div>
  52. </div>
  53. )
  54. }
  55. }
  56. export default Create;

参数说明

root{String} 表格id
data{Array} 表格内部数据,用户更改数据后,会自动更新source,不建议设置在父组件的state上
menus{Array[Object...]} 匹配菜单选择 => value 菜单内容 | required 是否显示必填,默认false,最后提交做校验
matchs{Array} 选择后的匹配结果
updateMatchs{Function} 更新用户选择匹配后的数据,返回最新的matchs

线上预览

线上预览地址