index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import React, { PureComponent } from 'react';
  2. import { connect } from 'react-redux';
  3. import * as config from '../config.js';
  4. const $ = require('jquery');
  5. $.DataTable = require('datatables.net');
  6. let dt = null;
  7. let propsobj=null;
  8. class dataTable extends PureComponent {
  9. // constructor(props){
  10. // super(props);
  11. // this.handleColumnVisible=this.handleColumnVisible.bind(this);
  12. // }
  13. render() {
  14. const { columnsData } = this.props;
  15. return (
  16. <div>
  17. <table ref={el => this.el = el} className="table table-bordered table-hover table-striped w-100">
  18. {/* <thead dangerouslySetInnerHTML={{__html: this.props.thead}} /> */}
  19. <thead>
  20. <tr>
  21. {
  22. columnsData.map((item,index) => {
  23. //console.log(item.get('联系人'));
  24. return (<th key={index}>{item.get('columnsName')}</th>)
  25. })
  26. }
  27. </tr>
  28. </thead>
  29. </table>
  30. </div>
  31. );
  32. }
  33. componentDidMount() {
  34. this.props.onRef(this);
  35. propsobj=this.props;
  36. this.$el = $(this.el);
  37. dt = this.$el.DataTable(
  38. {
  39. "language": {
  40. "paginate": {
  41. "next": "&nbsp;&nbsp;",
  42. "previous": "&nbsp;&nbsp;"
  43. },
  44. },
  45. ordering: false,
  46. processing: true,
  47. serverSide: true,
  48. responsive: true,
  49. autoWidth: true,
  50. info: false,
  51. searching: true,
  52. dom: 'lBrtip',
  53. lengthChange: false,
  54. 'ajax': {
  55. url: config.CLD2API + this.props.url,
  56. type: 'get',
  57. "dataSrc": function ( res ) {
  58. let bindDataEvend=propsobj.columnBindEvent(res);
  59. return bindDataEvend.data;
  60. }
  61. },
  62. columns: this.props.columns,
  63. }
  64. );
  65. // td2.clear();
  66. //console.log(td2.search('123', false, false));
  67. //td2.row.add({ 'DT_RowId': '0', 'clientname': '21dd23' });
  68. //td2.draw();
  69. //console.log($.DataTable.column(2));
  70. //this.$el.dataTable().search('123').draw();
  71. //dt.search('123').draw();
  72. }
  73. handleSearch(filter) {
  74. dt.search(JSON.stringify(filter)).draw();
  75. // console.log(value);
  76. }
  77. handleColumnVisible(index,visible){
  78. //console.log(index);
  79. // let visible=localStorage.getItem('contact_client_Column_'+index);
  80. //console.log(visible);
  81. // let column=dt.columns(index);
  82. // console.log(column.visible());
  83. // //console.log(!column.visible());
  84. // column.visible(false);
  85. // setTimeout(() => {
  86. // console.log('dd');
  87. // column.visible(1);
  88. // }, 350);
  89. let column=dt.columns(index);
  90. //column.visible(visible);
  91. //let visible=1;
  92. let boolVisible=true;
  93. if(visible==='false'||visible===false){
  94. boolVisible=false;
  95. }
  96. if(boolVisible){
  97. column.visible(1);
  98. }else{
  99. column.visible(0);
  100. }
  101. //column.visible(visible);
  102. }
  103. }
  104. const mapStateToProps = (state) => {
  105. return {
  106. }
  107. }
  108. const mapDispathToProps = (dispatch) => {
  109. return {
  110. ddd(){
  111. }
  112. }
  113. }
  114. export default connect(mapStateToProps, mapDispathToProps)(dataTable);
  115. //export default dataTable;