Jrg.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import * as React from 'react';
  2. import {TabulatorFull as Tabulator} from "tabulator-tables"; //import Tabulator library
  3. import './Tabulator.css';
  4. export default function Jrg({data}) {
  5. const myRef = React.useRef();
  6. const myTable = React.useRef(null);
  7. React.useEffect(() => {
  8. myTable.current = new Tabulator(myRef.current, {
  9. index: "key",
  10. height: 600,
  11. data: data, //link data to table
  12. reactiveData: false, //enable data reactivity
  13. dataTreeStartExpanded:true,
  14. dataTree: true,
  15. selectableRows:1, //make rows selectable
  16. editTriggerEvent:"dblclick", //trigger edit on double click
  17. dataTreeStartExpanded:function(row, level){
  18. //console.log(row);
  19. //console.log(level);
  20. return true; //expand rows where the "driver" data field is true;
  21. },
  22. columns: [ //Define Table Columns 序号", "名称", "取费基数", "计算基础","费率", "金额", "类别
  23. {title:"序号", field:"序号", width:80, headerSort:false,}, //never hide this column
  24. {title:"名称", field:"名称", width:150, headerSort:false, formatter:"textarea"}, //hide this column first
  25. {title:"金额", field:"金额", width:100, formatter:"money", },
  26. {title:"类别", field:"类别", width:100, formatter:"textarea"},
  27. ]
  28. });
  29. myTable.current.on("cellDblClick", function(e, cell){
  30. //e - the click event object
  31. //cell - cell component
  32. console.log(cell);
  33. });
  34. //myTable.current.on("rowSelected", handleSelect);
  35. }, [data]);
  36. return (
  37. <div ref={myRef}>
  38. </div>
  39. );
  40. }