Tbxx.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 Tbxx({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:150, headerSort:false, formatter:"textarea"}, //hide this column first
  24. {title:"金额", field:"金额", width:150, headerSort:false, formatter:"money", },
  25. {title:"暂估价", field:"暂估价", width:100, headerSort:false, formatter:"money"},
  26. {title:"安全文明施工费", field:"安全文明施工费", width:150, headerSort:false, formatter:"money"},
  27. {title:"规费", field:"规费", width:150, headerSort:false, formatter:"money"},
  28. ]
  29. });
  30. myTable.current.on("cellDblClick", function(e, cell){
  31. //e - the click event object
  32. //cell - cell component
  33. console.log(cell);
  34. });
  35. //myTable.current.on("rowSelected", handleSelect);
  36. }, [data]);
  37. return (
  38. <div ref={myRef}>
  39. </div>
  40. );
  41. }